How to set in a middleware a variable accessible in all my application?

前端 未结 4 1884
栀梦
栀梦 2021-02-13 21:39

I am using Ruby on Rails 3 and I am trying to use middlewares in order to set a variable @variable_name accessible later in controllers.

For example my midd

4条回答
  •  终归单人心
    2021-02-13 22:43

    Have you tried creating a Ruby global variable?

    def call(env)
      $account ||= Account.find(1)
    
      @app.call(env)
    end
    

    and

    <%= debug $account %>
    

提交回复
热议问题