# Unable to set default\_url\_options\[:host\] for Action Mailer

**URL:** <https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541>\
**Category:** Rails\
**Created:** [September 2, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541 "2008-09-02T23:59:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [September 2, 2008, 11:59pm UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541/1 "2008-09-02T23:59:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [September 3, 2008, 5:06pm UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541/2 "2008-09-03T17:06:03Z")

</div>

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](http://railswheels.com)

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [September 4, 2008, 12:41am UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541/3 "2008-09-04T00:41:35Z")

</div>

Mark Reginald J. wrote:

> Have you restarted your development server?

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

---

<div class="post-metadata">

**Author:** ![crucoba](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@crucoba](https://www.ruby-forum.com/u/crucoba)\
**Post date:** [April 21, 2010, 5:54am UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-host-for-action-mailer/147541/4 "2010-04-21T05:54:21Z")

</div>

> 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.](http://github.com/ryanb/nifty-generators)). 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
