views:

33

answers:

2

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.

+2  A: 

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.

Chris Heald
Thanks. I ended up changing the environment (relatively easy, actually) and now everything works as intended.
egarcia
A: 

I am afraid this answer isn't terribly helpful.

The railsy way is to have environments differ only in configuration (asset host, database etc.) for different environments. So a different database with users having dummy or test email addresses would be easiest way to go about it.

If you are generally cloning from Production, I recommend updating emails of all users, either through script/dbconsole or script/console or just a plain simple rake task.

And if you want to limit / control the features, then I'd recommend doing that through source control, i.e. by have different revisions deployed.

Swanand