- Add
gem 'rails_12factor'
to your Gemfile. This will add error logging and the ability for your app to serve static assets. bundle
- Run
RAILS_ENV=production rake db:create db:migrate db:seed
- Run
rake secret
and copy the output - From the command line:
export SECRET_KEY_BASE=output-of-rake-secret
- To precompile your assets, run
rake assets:precompile
. This will create a folderpublic/assets
that contains all of your assets. - Run
RAILS_ENV=production rails s
and you should see your app.
Remember to clobber your assets (rake assets:clobber
) and re-precompile (rake assets:precompile
) if you make changes.
in Rails 5, you don't need the rails_12factor instead in step 7 add RAILS_SERVE_STATIC_FILES=true like this:
RAILS_SERVE_STATIC_FILES=true RAILS_ENV=production bundle exec rails s
Do steps 4 and 5 BEFORE step 3 (i.e. add your secret key base environment variable otherwise you cant run the rake commands.
finally its important that in step 6 you prefix with
RAILS_ENV=production