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.
You need to add the following to your app/controllers/application.rb model :user That way rails knows to load the class definition before getting your model from the session. Cheers, Chris On Sat, 26 Mar 2005 16:50:36 +0000, Robert Lally <rob.lally-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks, that works. Can you explain why this is necessary? Why can''t rails unmarshal objects that it had no problems marshalling? It reminds me of classloader weirdness in java ... R.> Chris McGrath wrote: > > You need to add the following to your app/controllers/application.rb > > model :user > > That way rails knows to load the class definition before getting your > model from the session. > > Cheers, > > Chris > > > On Sat, 26 Mar 2005 16:50:36 +0000, Robert Lally <rob.lally-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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.
On Sun, 27 Mar 2005 12:58:11 +0100, Robert Lally <rob.lally-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks, that works. Can you explain why this is necessary? Why can''t > rails unmarshal objects that it had no problems marshalling? It > reminds me of classloader weirdness in java ...It''s hard to read something when you don''t know what you''re reading. To get all the methods in a class Ruby needs the class to be defined, it can''t just guess it, so you''ll need to load the class first. -- Phillip Hutchings http://www.sitharus.com/ sitharus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org / sitharus-QrR4M9swfipWk0Htik3J/w@public.gmane.org
My question ( and associated confusion ) comes from the fact that the interpreter knows what the class is, the class has certainly been defined; it has already been used in this session - the server hasn''t been restarted, the same instance of the ruby interpreter created, modified and marshalled the object out to the session file. Then, when it tries to read it back in, it has forgotten all about the class definition. R.> Phillip Hutchings wrote:> On Sun, 27 Mar 2005 12:58:11 +0100, Robert Lally <rob.lally-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>Thanks, that works. Can you explain why this is necessary? Why can''t >>rails unmarshal objects that it had no problems marshalling? It >>reminds me of classloader weirdness in java ... > > > It''s hard to read something when you don''t know what you''re reading. > To get all the methods in a class Ruby needs the class to be defined, > it can''t just guess it, so you''ll need to load the class first. >