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

前端 未结 4 1880
栀梦
栀梦 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:30

    You can have a cattr_accessor :my_var in any model and set this variable from middleware by

      MyModel.my_var = 'something'
    

    And you can access this anywhere in the application.

提交回复
热议问题