I have 3 separate staging servers set up in capistrano (and may have more at some point). For example:
staging.example.com
staging2.example.com
staging3.example.com
The capfile for each specifies the same environment though:
set :rails_env, 'staging'
… and in `config/environments/staging.rb I’ve had to define default url options:
config.action_mailer.default_url_options = { host: 'staging.example.com' }
Unfortunately this eventually results in using the wrong server at some point. For example, while testing on staging2 you could get an email with “staging” set in the url… click it without thinking and then you’re on the wrong server.
I didn’t want to add a separate environment file for each staging server since there may be quite a few at some point and this is really the only change that is different per server, since it’s the hostname.
Is there any way to get around this without using a separate environment file per staging host? Is it possible to use capistrano’s :web setting as the host url?
role :web, "staging2.example.com"
I ended up using an APP_CONFIG variable loaded from a yml file on each server as described in this related question: Re-source .bashrc when restarting unicorn?
Also, the original idea for the APP_CONFIG came from Railscast #226.