Cameron Yule

Rails staging environment

It’s easy to forget that Rails isn’t limited to the default development, test and production environments and I’ve found a custom staging environment comes in useful.

A staging environment is identical to production in terms of caching and performance, but allows you to target configuration settings for testing on your live server.

The common use case for me has been commerce applications where you can use the staging environment to automatically switch to your payment provider testing account while everything else is as per production.

Here’s how you can get a staging environment up and running.

  1. Copy production.rb to staging.rb in config/environments
  2. Add a staging entry to your config/database.yml
  3. Assuming your staging DB exists, that’s it!

You can then test it out with mongrel

ruby script/server -e staging

or alternatively if you use Phusion Passenger (mod_rails)

<VirtualHost XX.XX.XX.XX:80> 
  …
  RailsEnv staging  
</VirtualHost>

Published on October 26, 2008 in Programming
1 Comment