Stating CONSTANT values in a Ruby on Rails application
I am using Ruby on Rails 3.0.7 and I would like to state somewhere some CONSTANT values that is accessible by all classes in the application. I will use mentioned constants mostly for "global" validation purposes but I am considering to use those also for implement an authorization system.
Where and how I have to state 开发者_运维技巧these constants? What do you advice about?
why dont u create a .rb file in
config/initilizers directory
and define your constants there.
PS:-- you need to restart your server to access those variables.
One place for this in Rails 3 is config/application.rb
(module YourAppName, class Application) along with some of the Rails configuration lines. Some constants may also fit very well with your model classes, so you might want to consider this on a case-by-case basis.
You can either use an initializer or a simple yml file, loaded at startup - look at EnvYAML recipe at http://railswizard.org/ for example.
精彩评论