Global variable in Rails

后端 未结 4 2157
一生所求
一生所求 2021-02-14 10:58

I have a feedback form in my Rails application. The feedback form requires initializing of the @support variable, and it should be visible on every page. The initialization is v

4条回答
  •  自闭症患者
    2021-02-14 11:43

    you can use a helper method (in the application controller) to initialize the support variable . Something like this :

    class ApplicationController < ..
       ...
       helper_method :my_var
    
       def my_var
          @support = Support.new(:id => 1)
       end
       ...
    
     end
    

提交回复
热议问题