开发者

how call method logged_in in rails from model?

开发者 https://www.devze.com 2023-02-18 06:14 出处:网络
actually i use restful-authentication but ai need ca开发者_开发百科ll method logged_in from MODEL (no controller) distinct of user.

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

精彩评论

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