Neville Burnell
2005-Mar-09 06:48 UTC
Confused about extending the login generator ''user''
I''ve been using the login generator ''out of the box'' for simple authentication, and its been working fine. Now I want to extend it by simply adding ''type_id'' field which links to my ''user_types'' table, but I''m hitting: #<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.> 1) My application.rb is straight from the README, ie: Require_dependency "login_system" class ApplicationController < ActionController::Base include LoginSystem model :user end 2) My user_model.rb is a little different because I have defined the relationship to the type table, ie class MybmsUser < ActiveRecord::Base belongs_to: user_type 3) I''ve added the ''user_type_id'' to my ''users'' table and created the ''user_types'' table and user_types model. If I comment out the ''belongs_to: user_type'' then the app runs. If I leave it in then I get the failure above. I was hoping to be able to do something like this in my controller - am I off base? @user = @ession[''user''] @type = @user.type Do I need to ''require'' the ''user_type'' somewhere? Thanks, Neville
Sam Goldman
2005-Mar-09 07:26 UTC
Re: Confused about extending the login generator ''user''
I believe I know the answer to your question but I am not sure. In your view you are accessing an object of class UserType, but there is no such class definition in the context of the view. The reason that "model :user" is in the ApplicationController is to fix this for the User class (I think I reported this one). I guess adding "model: UserType" to application.rb will fix this. HTH, Sam
Jarkko Laine
2005-Mar-09 07:59 UTC
Re: Confused about extending the login generator ''user''
On 9.3.2005, at 08:48, Neville Burnell wrote:> If I comment out the ''belongs_to: user_type'' then the app runs. If I > leave it in then I get the failure above.This should be "belongs_to :user_type". The colon means that the following name (here user_type) is a Ruby symbol (http://onestepback.org/articles/tdddemo/rubysymbols.html). //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Stian Grytøyr
2005-Mar-09 08:52 UTC
Re: Confused about extending the login generator ''user''
Neville Burnell <Neville.Burnell-uEDVyssJ3mUpAS55Wn97og@public.gmane.org> wrote:> I''ve been using the login generator ''out of the box'' for simple > authentication, and its been working fine. > > Now I want to extend it by simply adding ''type_id'' field which links to > my ''user_types'' table, but I''m hitting: > > #<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.>You might want to consider storing just the user_id in the session. That way you''d have to fetch the user from the db whenever you need more than the user''s id, but it also saves you from having to deal with issues like the above. -- Regards, Stian Grytøyr
Jarkko Laine
2005-Mar-09 08:58 UTC
Re: Confused about extending the login generator ''user''
On 9.3.2005, at 10:52, Stian Grytøyr wrote:> > You might want to consider storing just the user_id in the session. > That way you''d have to fetch the user from the db whenever you need > more than the user''s id, but it also saves you from having to deal with > issues like the above.This also helps keeping the session files moderate even when the userbase grows larger. Fetching a single user object from the database is anyway a cheap, index-driven operation. //jarkko -- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Eric Ocean
2005-Mar-09 09:02 UTC
Re: Confused about extending the login generator ''user''
Neville, here''s what I do: I have a members table with a has_one relationship to the users table. In the users table, I added a member_id field, and added belongs_to :member at the top of my model class for the user table. I access that relationship like this in my Members controller: def index @user = @session[''user''] @member = @user.member end HTH, Eric On Mar 8, 2005, at 10:48 PM, Neville Burnell wrote:> I''ve been using the login generator ''out of the box'' for simple > authentication, and its been working fine. > > Now I want to extend it by simply adding ''type_id'' field which links to > my ''user_types'' table, but I''m hitting: > > #<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.> > > 1) My application.rb is straight from the README, ie: > > Require_dependency "login_system" > > class ApplicationController < ActionController::Base > include LoginSystem > model :user > end > > 2) My user_model.rb is a little different because I have defined the > relationship to the type table, ie > > class MybmsUser < ActiveRecord::Base > belongs_to: user_type > > > 3) I''ve added the ''user_type_id'' to my ''users'' table and created the > ''user_types'' table and user_types model. > > If I comment out the ''belongs_to: user_type'' then the app runs. If I > leave it in then I get the failure above. > > I was hoping to be able to do something like this in my controller - am > I off base? > > @user = @ession[''user''] > @type = @user.type > > Do I need to ''require'' the ''user_type'' somewhere? > > Thanks, > > Neville > > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Erich Ocean
2005-Mar-09 09:07 UTC
Re: Confused about extending the login generator ''user''
On Mar 9, 2005, at 1:02 AM, Eric Ocean wrote:> Neville, here''s what I do: > > I have a members table with a has_one relationship to the users table. > In the users table, I added a member_id field, and added > > belongs_to :member > > at the top of my model class for the user table. > > I access that relationship like this in my Members controller: > > def index > @user = @session[''user''] > @member = @user.member > endJust to be clear, I have has_one :user at the top of my Member controller. I didn''t see in your question that you are actually doing this. Best, Eric
Tobias Luetke
2005-Mar-09 14:22 UTC
Re: Confused about extending the login generator ''user''
Check the readme which the login generator creates. You need to add following things to your applicaiton.rb : require_dependency "login_system" class ApplicationController < ActionController::Base include LoginSystem model :user [...] On Wed, 9 Mar 2005 17:48:52 +1100, Neville Burnell <Neville.Burnell-uEDVyssJ3mUpAS55Wn97og@public.gmane.org> wrote:> I''ve been using the login generator ''out of the box'' for simple > authentication, and its been working fine. > > Now I want to extend it by simply adding ''type_id'' field which links to > my ''user_types'' table, but I''m hitting: > > #<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.> > > 1) My application.rb is straight from the README, ie: > > Require_dependency "login_system" > > class ApplicationController < ActionController::Base > include LoginSystem > model :user > end > > 2) My user_model.rb is a little different because I have defined the > relationship to the type table, ie > > class MybmsUser < ActiveRecord::Base > belongs_to: user_type > > 3) I''ve added the ''user_type_id'' to my ''users'' table and created the > ''user_types'' table and user_types model. > > If I comment out the ''belongs_to: user_type'' then the app runs. If I > leave it in then I get the failure above. > > I was hoping to be able to do something like this in my controller - am > I off base? > > @user = @ession[''user''] > @type = @user.type > > Do I need to ''require'' the ''user_type'' somewhere? > > Thanks, > > Neville > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Tobias Luetke
2005-Mar-09 14:23 UTC
Re: Confused about extending the login generator ''user''
This is great advice if you are into doing a lot of extra for the same thing ... :)> You might want to consider storing just the user_id in the session. > That way you''d have to fetch the user from the db whenever you need > more than the user''s id, but it also saves you from having to deal with > issues like the above.-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog
Stian Grytøyr
2005-Mar-09 14:47 UTC
Re: Confused about extending the login generator ''user''
Tobias Luetke <tobias.luetke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is great advice if you are into doing a lot of extra for the same > thing ... :)I basically do two things with the user that''s stored in the session: 1) Check if the user is logged in. 2) Save the logged-in user''s id in some relationship, i.e. @entry.author_id = @session[''user_id''] For everything else I actually prefer to fetch the user from the db, so that I know I have up-to-date data. But either way is fine, I''m sure :) -- Regards, Stian Grytøyr
Neville Burnell
2005-Mar-09 22:26 UTC
RE: Confused about extending the login generator ''user''
This sounds like the way to go ... are there any drawbacks, ie, why not do this ''out of the box''? -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Tobias Luetke Sent: Thursday, 10 March 2005 1:24 AM To: stian-hVTu40dgFLfR7s880joybQ@public.gmane.org; rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] Confused about extending the login generator ''user'' This is great advice if you are into doing a lot of extra for the same thing ... :)> You might want to consider storing just the user_id in the session. > That way you''d have to fetch the user from the db whenever you need > more than the user''s id, but it also saves you from having to deal > with issues like the above.-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://www.hieraki.org - Open source book authoring http://blog.leetsoft.com - Technical weblog _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails