Archive for the ‘rails constants’ tag
Rails Constants: Location matters
Rails framework provides a standard location for defining application specific constants. All default constants go in constant/environment.rb and any environment specific overrides go in config/environments/<env>.rb file. Normally, any constant that is overridden in environment specific file takes precedence. However, there is a catch. If a constant is defined outside of Rails::Initializer.run block then it overrides all other definition preceding it.
Hence, when defining constants in default config/environment.rb file, beware:
require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| A_CONSTANT = "value" end # Do not define environment specific constants here.
Enjoy!