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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With