pixelearth
pixelearth

Reputation: 14610

in rails set config.action_mailer.default_url_options to whatever the current host of the app is?

How can I dynamically set the host in a config/environments/production.rb:

config.action_mailer.default_url_options = { :host => THE_HOST}

This is so the app works correctly when in staging and when in production. Our staging server is stage.app.com, and links need to go there.

Upvotes: 5

Views: 5334

Answers (2)

Oliver
Oliver

Reputation: 851

Add this to a before filter in application_controller:

ActionMailer::Base.default_url_options = {:host => request.host_with_port}

Upvotes: -2

nicholaides
nicholaides

Reputation: 19489

In config/environments/production.rb do this:

config.action_mailer.default_url_options = { :host => 'app.com' }

and in config/environments/staging.rb do this:

config.action_mailer.default_url_options = { :host => 'stage.app.com' }

As @BrettBender commented:

You do not need to dynamically set the host. For an app in production, production.rb will be evaluated. For an app running in staging environment, rails will load the staging file automatically (same with development or any custom environments you define)

Upvotes: 5

Related Questions