rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org
2006-Sep-23 06:10 UTC
current_user
What do I need to do to be able to use an acts_as_authenticated current_user in a model? Error:You have a nil object when you didn''t expect it! The error occured while evaluating nil.login -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org wrote:> What do I need to do to be able to use an acts_as_authenticated > current_user in a model? > > > Error:You have a nil object when you didn''t expect it! > The error occured while evaluating nil.login > > >Short answer, you can''t (at least not easily). current_user is a controller method and therefore the model doesn''t have access to it (Rails is all about Model-View-Controller separation, remember). There''s been a fair amount of discussion on these lists about accessing the user from the model, including a few MVC-breaking workarounds. Quick google should dig them out. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> What do I need to do to be able to use an acts_as_authenticated > current_user in a model?You really shouldn''t. And, unless you make some horrible hacks, you can''t. The easiest thing to do is just pass the user object as a parameter to whatever model method you''re using. Cheers Starr -- Check out my blog for startups and upstarts: www.thebootstrapnation.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
You need to populate a class variable in your User model from your controller so that other models can access it. See userstamp (http:// delynnberry.com/pages/userstamp/) as an example. -- Building an e-commerce site with Rails? http://www.agilewebdevelopment.com/rails-ecommerce On Sep 22, 2006, at 11:10 PM, rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org wrote:> > What do I need to do to be able to use an acts_as_authenticated > current_user in a model? > > > Error:You have a nil object when you didn''t expect it! > The error occured while evaluating nil.login > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---