how call method logged_in in rails from model?
actually i use restful-authentication but ai need ca开发者_开发百科ll method logged_in from MODEL (no controller) distinct of user.
can you help me...
example:
modelx.rb
def price
if logged_in?
@product.price = current_user.prices
else
@product.price = 0
end
end
It's a better design to pass that information in from where you are calling the method.
def price(logged_in = false)
if logged_in
@product.price = current_user.prices
else
@product.price = 0
end
end
Calling it from the controller or view:
@modelx.price(logged_in?)
精彩评论