How can i create an attribute in a controller class, that can be seen inside all the actions and all the view related to this controller? thanks
在Controller中创建一个instance variable
,并确保为该变量提供attr_accessor
,以便所有视图都可以访问它。
Create before filter in your controller
For Example:
before_filter :example
def example
@variable = true
end
Now @variable is accessible in every action as well as views
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.