Ara*_*aju -1 ruby variables scope ruby-on-rails ruby-on-rails-4.1
我@event在控制器中有此变量,我想@event在所有视图中访问此变量。我不想将其设为全局变量。还有其他方法可以做到吗?我正在使用Rails 4.1。
小智 5
在ApplicationController的before_action中初始化它吗?
class ApplicationController < ActionController::Base
before_action :init
def init
@event = ...
end
end
Run Code Online (Sandbox Code Playgroud)