The usual way of storing Rails configuration data are YAML files. In one of our previous posts, we talked about proper way of dealing with Rails configuration.
gem install global
or add the following line into
gem 'global', '~> 0.1'
In addition to default configuration variables:
Global.configure do |config| config.environment = "YOUR_ENV_HERE" config.config_directory = "PATH_TO_DIRECTORY_WITH_FILES" end
All files are excluded by default due to security reasons.
WARNING!!! Don not include files that contain protected information – like api keys or credentials – because they will be accessible from the Browser console.
Require global file in
/* = require global-js */
In case you need different configurations for different parts of your application, you should create files manually.
If your application has
For instance, you have config file
global/hosts.yml with hosts settings for api and web:
development: web: localhost api: api.localhost production: web: myhost.com api: api.myhost.com
After that you have access to
Global.hosts.web => "localhost"
And in production environment:
Global.hosts.web => "myhost.com"
For more details, check out the source code and documentation on github.