Hi,
I am using Restful authentication for user authentication.
I want the current logged in user object in my model property.rb
Problem is current_user is not working on model.
How can I fix this I need that?
Please help me out.
Thanks,
Mike
Hi,
I am using Restful authentication for user authentication.
I want the current logged in user object in my model property.rb
Problem is current_user is not working on model.
How can I fix this I need that?
Please help me out.
Thanks,
Mike
On 16 Sep 2010, at 09:31, Mike D. wrote:
I am using Restful authentication for user authentication.
I want the current logged in user object in my model property.rb
Problem is current_user is not working on model.How can I fix this I need that?
You have two options:
The first method respects the separation of MVC better, the second can
be more convenient in some cases. It’s up to you to decide the best
route.
Best regards
Peter De Berdt
Mike D. wrote:
Hi,
I am using Restful authentication for user authentication.
[…]
This isn’t directly related to your issue…but if you don’t mind a bit
of advice, I highly recommend removing restful_authentication from your
project as soon as possible. It relies on unmaintainable generated
code, and so is needlessly hard to work with. I recommend Authlogic
instead.
Thanks,
Mike
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
The third option is to make virtual attribute on the model and always
set it when needed in the controller
class Model
attr_accessor :current_user
def some_method
if current_user.admin?
#foo
else
#bar
end
end
end
class FoosController
def index
m = Model.find(…)
m.current_user = current_user
m.some_method()
end
end
Marnen: What’s so ‘unmaintainable’ in your opinion?
Robert Pankowecki
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs