Model object in session problems

R

Rob Lally

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.
 
R

Rob Lally

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

R.
 
R

Rob Lally

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 said:
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'.

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

R.

Rob said:
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.
 
M

Moses Hohman

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

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 said:
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'.
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top