Unable to set default_url_options[:host] for Action Mailer

I am attempting to provide ActionMailer with the request host needed to
generate a url.

Here is my code:

In config/environments/development.rb
config.action_mailer.default_url_options = { :host =>
“development_url.com” }

and in config/environments/production.rb
config.action_mailer.default_url_options = { :host =>
“production_url.com” }

When I run the above code ActionMailer fails, and tells me that I never
provided it with the request host. I think ActionMailer is a dirty
liar.

Any suggestions for a fix?

David Crockett wrote:

config.action_mailer.default_url_options = { :host =>
“production_url.com” }

When I run the above code ActionMailer fails, and tells me that I never
provided it with the request host. I think ActionMailer is a dirty
liar.

Any suggestions for a fix?

Have you restarted your development server?

If so, try putting it inside your mailer class:

default_url_options[:host] = RAILS_ENV != production ?
“development_url.com” : “production_url.com”


Rails Wheels - Find Plugins, List & Sell Plugins -
http://railswheels.com

Mark Reginald J. wrote:

Have you restarted your development server?

Nope - restarting the server solved the problem. Thanks for the help.

If so, try putting it inside your mailer class:

default_url_options[:host] = RAILS_ENV != production ?
“development_url.com” : “production_url.com”

I would recommend using Ryan B. nifty generators gem
(GitHub - ryanb/nifty-generators: A collection of useful Rails generator scripts.). This lets you generate a
nifty_config file (actually by default called app_config.yml) which lets
you access variables which depend on production environment by doing
APP_CONFIG[:domain] or some some such madness. Definitely beats the
above method if you have to use that information in more than one place
(DRY).

Chris