2011-03-22 48 views
1

实际上,我使用restful-authentication,但是ai需要从MODEL(无控制器)不同的用户调用方法logged_in。如何在模型的rails中调用方法logged_in?

你可以帮我...

例如:

modelx.rb

def price 
    if logged_in? 
     @product.price = current_user.prices 
    else 
     @product.price = 0 
    end 
    end 

回答

4

这是一个更好的设计来传递从正在调用该方法的信息。

@modelx.price(logged_in?) 

def price(logged_in = false) 
    if logged_in 
    @product.price = current_user.prices 
    else 
    @product.price = 0 
    end 
end 

从控制器或视图中调用它

相关问题