Reputation: 13
Can someone explain to me what the Rails environments are and what they do? I have tried researching myself, but could not find anything. From what I gather, the environments are:
Upvotes: 2
Views: 5708
Reputation: 172
Here are some good reads about Rails Environments
http://teotti.com/use-of-rails-environments/
and
https://signalvnoise.com/posts/3535-beyond-the-default-rails-environments
good luck !!
Upvotes: 1
Reputation:
From what you have provided in your question, it seems that you are asking:
"What are the difference between each environment configuration in Rails?"
Rails comes packages with 3 types of environments. Each have its own server, database, and configuration. See Rails Guides: Configuration for more information on options available to you.
To set your Rails environment, you will want to enter in command line:
export RAILS_ENV=<env>
Where <env>
can be test
, development
, or production
. Setting this environment variable is crucial, as it will determine what gems are installed, or what env is touched when running rails console
or rails server
.
Included in configuration is the gemset used for the app. When you run rails new
, you will find a Gemfile with groups test
, development
, and production
. These groups correspond to the environment currently set. When the environment is set to one of those, running bundle install
installs all gems related to that group (and gems not listed in a group).
test
is designed for running tests/specs. This database will likely be bare bones, except for seeds you may call before running the suite. After each test is complete, the database will rollback to its state before the test began. I do not recommend launching rails server
, as running tests (via MiniTest or RSpec) will do this for you, and close the server once the suite is finished.
development
allows you to "test" your app with a larger database, typically a clone of production. This allows you to test actual real-world data without breaking production (the version that customers or end-users will experience). To view the development environment in action, change the RAILS_ENV
and launch rails server
. This is good for deciding how you want your pages to look (CSS, HTML). It is also good practice to briefly "test" your app yourself, clicking around making sure everything "looks" good and the JavaScript works.
production
is reserved for the customer and end-user. Configuration includes the actual domain of the app, which ports to use, and initializers or tasks to run. You do not want to play around with your database, as it may be customer-impacting. Ideally, the app should work as best as it can, since this is considered your "final product."
Upvotes: 3
Reputation: 32933
Each "environment" is really just a config. You can launch your app in various different modes, and the modes are called "environments" because they affect the app's behaviour in lots of different ways. Ultimately, though, they are just configs.
BTW you can't have looked very hard when you looked "everywhere", because i just googled "rails environment" and the top result was this
http://guides.rubyonrails.org/configuring.html
which is the official explanation of configuring the rails environment.
Upvotes: 2