Running a Rails site: development vs production

SundayMonday picture SundayMonday · Nov 26, 2011 · Viewed 15.5k times · Source

I'm learning Ruby on Rails. At the moment I'm just running my site locally with rails server in the OS X Terminal. What changes when a Rails site is run on a production box?

  • Is the site still started with rails server?
  • Any differences with how the db is setup?

Note: I'm running Rails 3.

Answer

Andrew picture Andrew · Nov 26, 2011

A rails app can be run in production calling rails server -e production, although 99% of the time you'll be serving on something like passenger or thin instead of WEBrick, which means there's a different command to start the server. (thin start -e production for instance)

This is a complicated question, but the best place to start learning about the differences would be to look at the specific environment.rb files. When rails boots up it starts with the environment file that matches the called environment, ie if you start it in development it begins by loading your development.rb file, or if you're in production it will load the production.rb file. The differences in environments are mostly the result of these differences in the various environment config files.

Basically if a Rails 3.1 app is in production mode, then by default it is not going to be compiling assets on the fly, and a lot of caching will be going on that isn't happening in development. Also, when you get error messages they will be logged but not rendered to the user, instead the static error page from your public directory will be used.

To get more insight into this, I would suggest reading the relevant rails guides:

Rails Initialization Guide: http://guides.rubyonrails.org/initialization.html

Rails Configuration Guide: http://guides.rubyonrails.org/configuring.html