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

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

[email protected] 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.

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