Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: differentiating staging from production

I've got a production server and a staging sever in which new features are tested before moving them to production. The staging server is physically different from the production one (different hosts with different urls), but it mimics it as much as possible (i.e. same packages, same gems, etc).

Rails.env = 'production' on both servers.

My problem is that in some cases I need different behaviour on staging than in production.

For example, a new feature might send massive emails to users on production; but while I'm testing it I'd rather have them sent to a 'test' email account.

What is the best way to detect the server I'm at?

I'd like to do it as "raily" as possible.

Thanks a lot.

like image 308
kikito Avatar asked Aug 12 '10 07:08

kikito


1 Answers

Generally, this is why you'd use different environments. Practically speaking, a staging environment is usually very close to production, but with things like real emails turned off.

You aren't limited to development/test/production - you can run under an environment named anything you want. Just create a config/environments/staging.rb file, set the values you want in there, and start your app with RAILS_ENV=staging - that's all there is to it. That way you can emulate your production environment, but twiddle features on or off as desired when you don't want them active before you actually go live.

like image 140
Chris Heald Avatar answered Nov 01 '22 01:11

Chris Heald