开发者

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?)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜