# Unable to set default\_url\_options on per environment basis

**URL:** <https://www.ruby-forum.com/t/unable-to-set-default-url-options-on-per-environment-basis/205891>\
**Category:** Rails\
**Created:** [April 18, 2011, 9:44am UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-on-per-environment-basis/205891 "2011-04-18T09:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 18, 2011, 9:44am UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-on-per-environment-basis/205891/1 "2011-04-18T09:44:50Z")

</div>

Im trying to set the default\_url\_options on a per environment basis  
but nothing is working. I keep getting “Missing host to link to!  
Please provide :host parameter or set default\_url\_options[:host]”

post.rb

def share\_all  
url = Rails.application.routes.url\_helpers.post\_url(self)  
if user.authentications.where(:provider =\> ‘twitter’).any?  
user.twitter\_share(url)  
end  
end

I’ve tried adding this to my config/environments/development.rb :

development.rb

config.action\_controller.default\_url\_options = {:host =\> “localhost:  
3000”}

which didn’t work so I tried it this way:

development.rb

config.action\_controller.default\_url\_options = {:host =\>  
“localhost”, :port =\> 3000}

And that didnt work so I tried just defining the method in the  
application controller but it didnt work either.

class ApplicationController \< ActionController::Base  
protect\_from\_forgery  
include ApplicationHelper  
def default\_url\_options  
{ :host =\> “[example.com](http://example.com)”}  
end  
end

What am I missing here? This is driving me nuts, thanks.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 18, 2011, 3:06pm UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-on-per-environment-basis/205891/2 "2011-04-18T15:06:59Z")

</div>

On Apr 17, 10:16pm, charles d [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> include ApplicationHelper  
> def default\_url\_options  
> { :host =\> “[example.com](http://example.com)”}  
> end  
> end
> 
> What am I missing here? This is driving me nuts, thanks.

I think you’re not setting default\_url\_options in the correct place -  
you’re using the named routes module in isolation (whereas normally  
that code would be called from within a controller or helper) so the  
stuff you’re doing to ApplicationController doesn’t come into place.

Rails.application.routes.default\_url\_options[:host]= ‘[example.com](http://example.com)’

seems to do the trick

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 20, 2011, 10:41pm UTC](https://www.ruby-forum.com/t/unable-to-set-default-url-options-on-per-environment-basis/205891/3 "2011-04-20T22:41:29Z")

</div>

Thanks that worked perfectly

On Apr 18, 6:05am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
