Reputation: 15107
I have a variable: site_name that will be different for various sites, but am not sure where to put it, in order to be accessible for all models/views/controllers? This variable should only be set once on server startup and be used after that throughout the site?
site_name ||= ENV['SITE'] == 'SiteA' ? "Awesome Site" : "Cool Site"
Where would i put this? in a variable? in a method? what location?
Upvotes: 0
Views: 66
Reputation: 46
Generally you would put this in config/environment.rb
. Or if you need to customize the variable based on your environment (production, development, test), you can put it in the corresponding file in config/environments/*.rb
. These files are read only on startup, so if you change the value you need to restart your rails application for them to take effect.
Also note that you should format it as follows:
Myapp::Application.config.site_name = ENV['SITE'] == 'SiteA' ? 'Awesome Site' : 'Cool Site'
and then access it in your application as:
Myapp::Application.config.site_name
Upvotes: 3