application wide global variable

Mellon picture Mellon · Dec 2, 2011 · Viewed 20.7k times · Source

In Rails, where should I define the variable which can be recognized by every layer of Rails stacks.

For example, I would like to have a CUSTOMER_NAME='John' variable which can be accessed in helper, rake task, controller and model. Where should I define this variable in Rails app?

I am using Rails v2.3.2

Answer

Paul Groves picture Paul Groves · Dec 2, 2011

In an initializer in /app/config/initializers all .rb files in here get loaded, I usually create one called preferences.rb for things like this.

See: http://guides.rubyonrails.org/configuring.html#using-initializer-files