Tatva-Artha

meaning of "it"

Archive for the ‘rails constants’ tag

Rails Constants: Location matters

without comments

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!

Written by admin

June 1st, 2009 at 9:42 pm

Posted in All,Technology

Tagged with ,