You know there are development, test and production environments on Ruby on Rails. This article shows you how to create new environment for your system.
We are currently working with:
- Ruby: 1.9.2
- Ruby on Rails: 3.0.5
How to refer environment name
You can refer environment name through Rails.env.
p Rails.env #=> "development"
Adding new environment
For example, you can add your new 'staging' environment by these steps. Follow these steps to add your new 'staging' environment.
- copy RAILS_HOME/config/environments/production.rb as RAILS_HOME/config/environmentsstaging.rb
- add staging section into database.yml
Then, create database, do migration, and start your staging server.
$ rake db:create RAILS_ENV=staging $ rake db:migrate RAILS_ENV=staging $ rails server -e stagingYes! You now have new 'staging' environment for your project.
gem setting
You can use different gems for your each environment. This situation, write your Gemfile as below.
group :development, :test do gem 'sqlite3-ruby' end group :staging, :production do gem 'mysql2', '0.2.7' endYou can reject unnecessary gems for specified environment.
$ bundle install --without test developmentsee: Bundler : Using Groups
This article is translated from Japanese.
No comments:
Post a Comment