How to create a new environment in Ruby on Rails?

I am trying to create a new environment (assembly) to use it with hudson.

I do this because I did not want to mix test databases with hudson test database.

+48
ruby-on-rails
Mar 03 '10 at 7:48
source share
4 answers

Assuming you want to create a hudson environment.

  • Create a new environment file in config/environments/hudson.rb . You can start by cloning an existing one, for example config/environments/test.rb
  • Add a new configuration block to config/database.yml for your environment.
  • Update any other configuration file that may be in the config folder with the new environment, some gems create their own ymls in the config folder.
  • What all.

Now you can start the server

 rails server -e hudson 

or start the console

 rails console hudson 

And so on.

If you are using an older version of Rails, the commands

 ruby script/server -e hudson ruby script/console hudson 
+79
Mar 03 '10 at 7:54
source share

Updated Answer for Rails 5

Create a new environment file:

 config/environments/staging.rb 

Modify the following files to add the 'staging' environment key

 config/cable.yml config/database.yml config/secrets.yml Gemfile (incase you have stage dependent gems) 

New environments can now be used as usual, for example, for:

rails server -e staging

rails console staging

Or do conditional checks:

 rails console staging, Rails.env.staging? 

A good place to start creating a new environment and modify these files is to copy production parameters.

+12
Dec 22 '16 at 5:13
source share

Create a config/environments/build.rb that will contain settings specific to your environment.
Add your new environment credentials to config/database.yml .

Rock'n'roll!

+1
Mar 03 '10 at 7:55
source share

If you use webpacker in your Rails 5 application, also be sure to update your config/webpacker.yml . If you forget to add a new environment to config/webpacker.yml , it will simply revert to using your production configuration.

0
Dec 20 '18 at 13:55
source share



All Articles