Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Missing host to link to! Please provide :host parameter or set default_url_options[:host]

I have been googling for about 90 minutes now and still don't have an answer to this. Where do I set default_url_options? I've already set it for config.action_mailer.default_url_options to solve this same bug elsewhere, but now I'm getting this error when trying to use a URL helper inside an RSpec spec. I have no idea where it's expecting default_url_options to be set.

 Failure/Error: listing_url(listing).should match(/\/\d+-\w+$/)  RuntimeError:    Missing host to link to! Please provide :host parameter or set default_url_options[:host]  # ./spec/routing/listing_routing_spec.rb:9:in `block (3 levels) in <top (required)>' 

This code has nothing to do with emails/ActionMailer, it just happens to need a URL instead of a path.

Any ideas?

like image 495
d11wtq Avatar asked Aug 28 '11 08:08

d11wtq


1 Answers

You need to add the following line at every environment:

config.action_mailer.default_url_options = { :host => "yourhost" }

That way, it can work in all environments and could be different from environment to environment. For example:

development.rb

config.action_mailer.default_url_options = { :host => "dev.yourhost.com" } 

test.rb

config.action_mailer.default_url_options = { :host => "test.yourhost.com" } 

production.rb

config.action_mailer.default_url_options = { :host => "www.yourhost.com" } 
like image 154
Carlos Castillo Avatar answered Sep 19 '22 21:09

Carlos Castillo