How to setup two host configs for Devise?
I am using Devise. I need to push the same rails project to two different heroku apps. Is there a way to setup different hosts for the two apps?
For concreteness, for appA, the production.rb should contain the config.action_mailer.default_url_options = {:host => 'appA.heroku.com'}
and for appB, the production.rb should contain config.action_mailer.default_url_options = {:host开发者_StackOverflow中文版 => 'appB.heroku.com'}
.
However, it seems that it is not possible to have both lines in the same production.rb.
You can use environment variables on your heroku instance to differentiate constants in your rails app.
For example:
# production.rb
config.action_mailer.default_url_options = { :host => ENV['ACTION_MAILER_HOST'] }
Then, on your local machine:
% cd /path/to/project/A
% heroku config:add ACTION_MAILER_HOST=appA.heroku.com
% cd /path/to/project/B
% heroku config:add ACTION_MAILER_HOST=appB.heroku.com
For reference and more examples, see this heroku article on environment variables.
You should use a config var for this. That way the value is set per heroku deployment and not in the source code. See the heroku documentation for more information.
精彩评论