Where to put Global variables in Rails 3

后端 未结 5 1776
旧时难觅i
旧时难觅i 2020-11-30 03:25

I used to put Global variables in environment.rb with my Rails 2.3.8 application such as:

MAX_ALLOWD_ITEMS = 6

It doesn\'t seem to work in

5条回答
  •  伪装坚强ぢ
    2020-11-30 04:08

    I don't know if the solution of adding variables to environment.rb would in fact work in Rails3 - to be specific, if you haven't defined the variable inside a module definition like so:

    module MyConfig
      Max_ints = 5
    end
    

    you won't be able to just use Max_ints, if you just include it as a bare definition. Or at least that's what I found happened when I experimented with this. I also think the suggestion to use the initializers/ folder is possibly a better solution in terms of ease of use. See Permanent variable in Rails

提交回复
热议问题