开发者

In my actions, when should I use @variable_name, only when I need it in a view?

开发者 https://www.devze.com 2023-02-20 05:16 出处:网络
Do I only prefix var names with @ i开发者_StackOverflow社区f I need that variable in a view?Basically you want to use @variable_name (instance variables) when you want to access these variables outsid

Do I only prefix var names with @ i开发者_StackOverflow社区f I need that variable in a view?


Basically you want to use @variable_name (instance variables) when you want to access these variables outside of the local scope, one example is using them in the view.

Another example:

before_filter :setup

def index
# can access @profile
end

private

def setup
  @profile = Profile.find(params[:profile_id])
end
0

精彩评论

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