开发者

Rails: differentiating staging from production

开发者 https://www.devze.com 2023-01-11 10:21 出处:网络
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

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消