Rails> = 3, the application itself is a module (lives in config/application.rb ). They can be saved in the application module.
module MyApplication SUPER_SECRET_TOKEN = "123456" end
Then use MyApplication::SUPER_SECRET_TOKEN to refer to the constant.
Rails> = 2.1 && <3 you must put them
- in
/config/initializers when the constant has an application scope - when a constant refers to a specific model / controller / helper, you can cover it inside the class / module itself
Prior to Rails 2.1 and initializers programmers were used to place application constants in environment.rb.
Here are some examples.
# config/initializers/constants.rb SUPER_SECRET_TOKEN = "123456" # helpers/application_helper.rb module ApplicationHelper THUMBNAIL_SIZE= "100x20" def thumbnail_tag(source, options = {}) image_tag(source, options.merge(:size => THUMBNAIL_SIZE) end end
Simone Carletti Jul 10 '09 at 6:52 2009-07-10 06:52
source share