1

Let's say I have an app that has the usual environments: development, staging, and production. Then let's say I have a set of tasks that I need to run in an environment where a specific set of configuration options have been overridden -- let's say the DB host -- and these scripts (and their overrides) need to run in each environment.

One solution that comes to mind is to create a whole set of environments for each of these special cases, i.e.: dboverride-development.rb, dboverride-staging, and dboverride-production. Each of these environments would inherit from its main environment, but then override the necessary configuration options. But this seems cumbersome and isn't at involves a lot of code replication.

Are there existing strategies or conventions for this use-case in rails (v4 specifically)?

1 Answer 1

0

You can use environment variables to override any specific options as shown in the Rails guides.

If you have a config/database.yml but no ENV['DATABASE_URL'] then this file will be used to connect to your database:

If you have both config/database.yml and ENV['DATABASE_URL'] set then Rails will merge the configuration together. To better understand this we must see some examples.

When duplicate connection information is provided the environment variable will take precedence:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.