Initializing Custom YML Configuration Variables for Different Environments in Rails
Another common problem that rails developers face while developing web applications that connect to multiple external systems and api’s is configuring the the same parameters for different environments.
The simplest way -
Add a folder to the config folder of your application
Add all the configuration in as a yml file, like how we use the database.yml with all the environments in it
sample file: config/google_api.yml
1 2 3 4 5 6 7 8 9 10
the &default_settings and *default_settings can be used to pass the same values into another yml
add the following to your rb file:
1 2 3 4 5 6 7 8 9 10 11
The above code adds all the yml files inside the folder we created(app_config) under the config folder to a hash(APP_CONFIG).
- Now we can use get the google analytics id with the following
This would return the corresponding configuration variable depending upon the environment.
Any questions on this, please feel free to ask. We’re here to help…