3

I am very confused about this whole rails deploy thing. The confusion is that whilst developing the whole app it has been in development mode, which is fine. Now that I will deploy it, are there ammendments I need to make to files to change the rails app to production mode before deploying, or does deploying autmatically do this?

I guess what I am asking is how do I switch from one environment to another?

Muhammed Bhikha
  • 4,881
  • 9
  • 36
  • 47

2 Answers2

5

No need to change any files just set shell variable RAILS_ENV=production on your server

Tolik Kukul
  • 1,996
  • 16
  • 26
  • how exactly do I do that? in terminal? – Muhammed Bhikha Dec 20 '12 at 20:19
  • 1
    yes. `export RAILS_ENV=production`. also I recomend you to not use rails s in production. Try passenger server(https://www.phusionpassenger.com/) or other – Tolik Kukul Dec 20 '12 at 20:21
  • I run the command but get no confirmation etc. How do I know if it is done or not? – Muhammed Bhikha Dec 20 '12 at 20:23
  • 2
    If your server restarts you will need to `export RAILS_ENV=production` again. You should put this in one of your config files, like `.bashrc` or `.zshrc`. Also I would recommend thin or unicorn instead of passenger. Their is nothing wrong with running `rails s`, just know that it runs webrick. You can always specify the server to run for instance you could just run this command `rails server thin -e production`, assuming you have thin in your Gemfile, this will start thin and put rails in production mode in one command. – mwoods79 Dec 20 '12 at 22:24
2

rails server -e production will put you in production mode.

ALSO...

By default rails 3.1 and later defer assets to the asset pipeline. So you either need to run rake assets:precompile or turn on serving assets in config/environments/production.rb.

# config/environments/production.rb
config.assets.compile = true

You also need to ensure that your production database is setup correctly in config/database.yml

Other than that you are good to go :)

If this is truly a production box you could also set an environment variable to 'production' as well. As explained by Anatoliy Kukul in another answer.

mwoods79
  • 1,608
  • 1
  • 13
  • 16
  • Hey mwoods79. You definitely SHOULD NOT set config.assets.compile = true. Use rake assets:precompile. Consider changing your answer. See this post: http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not – Benjamin Jun 28 '16 at 17:25
  • @Ben my answer still holds true. Whether it is a good idea or not is another conversation. After years of consulting I can think of at least 2 large enterprise applications that do this, and do this well. Both of those apps also set the `asset_host` to use a CDN. This is a great strategy. The first request compiles the asset and stores it in the CDN. All asset requests after that get served from the CDN. Works great. – mwoods79 Jun 29 '16 at 17:57