The following method defines constants and global variables in Rails. If you want to access any environment (development, testing, or product), it is defined in config/environment. rb.
For example:
BOOLEN_TRUE = 1
If you want your global variables to be determined by the Environment, configure
/Config/environments/development. rb
/Config/environments/test. rb
/Config/environments/production. rb
Note,
1> constants and global variables must all be in uppercase;
2> after global constants and variables are set, restart the server to load new settings.
PS. english version
I was recently faced with a common problem that I wanted to share.
During development there are times you need to specifiy a global or
Constant variable that will be shared throughout the entire
Application. In ColdFusion you wowould normally place something like this inApplication. cfm. In Rails I was uncertain how exactly to approach this. At first I thoughtApplication. rbFile made sense, but the more I thought about it I decided to take advantage of the config files.
Since my global variable was one that wocould be consistent regardless
Of environment (dev, test, and prod) I decided to place it in
Config/environment. rb. I placed this underRAILS_GEM_VERSIONConstant:
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '1. 1.2 ′
BASE_URL = 'HTTP: // mydomain.com /'
Now referencing this in any view can be done similar to any other variable:
<% = BASE_URL %>
If you need to specify globals that are specific to environment then I recommend placing them in their appropriate config file:
/Config/environments/development. rb
/Config/environments/test. rb
/Config/environments/production. rb
From: http://www.db75.com/new_blog? P = 262