[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Model object in session problems

Rob Lally

3/26/2005 10:13:00 AM

Hi,

I'm having a problem storing an AR model object in a session. Actually the problem doesn't seem to be related to storing
it in a session. The problem occurs when the session is deserialised on the next request.

When the user logs in I pop a User object (an AR model) into the session and redirect to the homepage. Then I see the
following error

<ActionController::SessionRestoreError: Session contained objects where the class definition wasn't available. Remember
to require classes for all objects kept in the session. The session has been deleted. (Original exception: undefined
class/module User [ArgumentError])>

Can anyone shed any light on my problem?


Thanks,

R.


4 Answers

Rob Lally

3/26/2005 4:52:00 PM

0

Sorry - just realised I sent this to the ruby list rather than the rails list.

R.

Rob Lally wrote:
> Hi,
>
> I'm having a problem storing an AR model object in a session. Actually
> the problem doesn't seem to be related to storing it in a session. The
> problem occurs when the session is deserialised on the next request.
>
> When the user logs in I pop a User object (an AR model) into the session
> and redirect to the homepage. Then I see the following error
>
> <ActionController::SessionRestoreError: Session contained objects where
> the class definition wasn't available. Remember to require classes for
> all objects kept in the session. The session has been deleted. (Original
> exception: undefined class/module User [ArgumentError])>
>
> Can anyone shed any light on my problem?
>
>
> Thanks,
>
> R.


Rob Lally

3/26/2005 5:31:00 PM

0

Thanks - that solves the problem.

I don't understand why it is necessary though. I assumed that the application had already required the User class and
the user file since this is reading in something it just created and wrote out. What am I missing?

R.


Moses Hohman wrote:

> If you "require 'user'" in your application.rb (so that it will be
> required in every controller), the problem should go away. The problem
> is, as I understand it, that the homepage controller does not
> automatically know to require 'user'.
>
> On Mar 26, 2005, at 10:52 AM, Rob Lally wrote:
>
>> Sorry - just realised I sent this to the ruby list rather than the
>> rails list.
>>
>> R.
>>
>> Rob Lally wrote:
>>
>>> Hi,
>>> I'm having a problem storing an AR model object in a session.
>>> Actually the problem doesn't seem to be related to storing it in a
>>> session. The problem occurs when the session is deserialised on the
>>> next request.
>>> When the user logs in I pop a User object (an AR model) into the
>>> session and redirect to the homepage. Then I see the following error
>>> <ActionController::SessionRestoreError: Session contained objects
>>> where the class definition wasn't available. Remember to require
>>> classes for all objects kept in the session. The session has been
>>> deleted. (Original exception: undefined class/module User
>>> [ArgumentError])>
>>> Can anyone shed any light on my problem?
>>> Thanks,
>>> R.


Moses Hohman

3/26/2005 5:37:00 PM

0

I assume that your login controller and your homepage controller are
different classes? In that case, while your login controller may
automatically require your user class definition, your homepage
controller won't. If that doesn't make any sense, then I'm
misunderstanding your situation and I'd have to see your code.

M

On Mar 26, 2005, at 11:31 AM, Rob Lally wrote:

> Thanks - that solves the problem.
>
> I don't understand why it is necessary though. I assumed that the
> application had already required the User class and the user file
> since this is reading in something it just created and wrote out. What
> am I missing?
>
> R.
>
>
> Moses Hohman wrote:
>
>> If you "require 'user'" in your application.rb (so that it will be
>> required in every controller), the problem should go away. The
>> problem is, as I understand it, that the homepage controller does not
>> automatically know to require 'user'.
>> On Mar 26, 2005, at 10:52 AM, Rob Lally wrote:
>>> Sorry - just realised I sent this to the ruby list rather than the
>>> rails list.
>>>
>>> R.
>>>
>>> Rob Lally wrote:
>>>
>>>> Hi,
>>>> I'm having a problem storing an AR model object in a session.
>>>> Actually the problem doesn't seem to be related to storing it in a
>>>> session. The problem occurs when the session is deserialised on the
>>>> next request.
>>>> When the user logs in I pop a User object (an AR model) into the
>>>> session and redirect to the homepage. Then I see the following
>>>> error
>>>> <ActionController::SessionRestoreError: Session contained objects
>>>> where the class definition wasn't available. Remember to require
>>>> classes for all objects kept in the session. The session has been
>>>> deleted. (Original exception: undefined class/module User
>>>> [ArgumentError])>
>>>> Can anyone shed any light on my problem?
>>>> Thanks,
>>>> R.
>



Rob Lally

3/26/2005 7:38:00 PM

0

Ooops,

Actually that doesn't solve the problem. In my attempts to figure out what was wrong I had taken out the code that
stored the object in the session and replaced it with a number. I can freely create User objects anywhere in the code so
'user' has already been required.

R.


Moses Hohman wrote:

> I assume that your login controller and your homepage controller are
> different classes? In that case, while your login controller may
> automatically require your user class definition, your homepage
> controller won't. If that doesn't make any sense, then I'm
> misunderstanding your situation and I'd have to see your code.
>
> M
>
> On Mar 26, 2005, at 11:31 AM, Rob Lally wrote:
>
>> Thanks - that solves the problem.
>>
>> I don't understand why it is necessary though. I assumed that the
>> application had already required the User class and the user file
>> since this is reading in something it just created and wrote out. What
>> am I missing?
>>
>> R.
>>
>>
>> Moses Hohman wrote:
>>
>>> If you "require 'user'" in your application.rb (so that it will be
>>> required in every controller), the problem should go away. The
>>> problem is, as I understand it, that the homepage controller does not
>>> automatically know to require 'user'.
>>> On Mar 26, 2005, at 10:52 AM, Rob Lally wrote:
>>>
>>>> Sorry - just realised I sent this to the ruby list rather than the
>>>> rails list.
>>>>
>>>> R.
>>>>
>>>> Rob Lally wrote:
>>>>
>>>>> Hi,
>>>>> I'm having a problem storing an AR model object in a session.
>>>>> Actually the problem doesn't seem to be related to storing it in a
>>>>> session. The problem occurs when the session is deserialised on the
>>>>> next request.
>>>>> When the user logs in I pop a User object (an AR model) into the
>>>>> session and redirect to the homepage. Then I see the following error
>>>>> <ActionController::SessionRestoreError: Session contained objects
>>>>> where the class definition wasn't available. Remember to require
>>>>> classes for all objects kept in the session. The session has been
>>>>> deleted. (Original exception: undefined class/module User
>>>>> [ArgumentError])>
>>>>> Can anyone shed any light on my problem?
>>>>> Thanks,
>>>>> R.
>>
>>
>
>
>