Raunak Joneja
Raunak Joneja

Reputation: 561

Missing host to link to! Please provide the :host parameter, for Rails 4

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

I randomly get this error at time, generally restarting the server fixes the issue for a while, and then it shows up again. I have added config.action_mailer.default_url_options = "localhost:3000", in the development and test.rb files.

Also, I have used include Rails.application.routes.url_helpers in one module to get access to the routes, I read this could be the reason I get these errors but removing it will leave me with no access to the routes.
The module is for the datatables gem.

Upvotes: 26

Views: 25883

Answers (4)

David
David

Reputation: 1191

For Rails 5, use:

Rails.application.routes.default_url_options[:host] = "XXX"

You can put this in a config/environments/ file (or any other initializer), or e.g. at the beginning of config/routes.rb.

Upvotes: 45

Ruben Cruz
Ruben Cruz

Reputation: 221

I had a similar error. The problem is in your configuration.

Try rewriting your configuration for your development.rb and test.rb like this:

config.action_mailer.default_url_options = { host: "localhost", port: 3000 }

Also check that your configuration in production.rb is written correctly like this:

config.action_mailer.default_url_options = { host: 'myherokuapp.herokuapp.com' }

Upvotes: 14

Rajarshi Das
Rajarshi Das

Reputation: 12320

You should write in the following way

For Development(development.rb)

config.action_mailer.default_url_options = { :host => "localhost:3000" }

In production (production.rb)

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

Upvotes: 25

Andy
Andy

Reputation: 135

You have updated the default url options for action mailer. URL helpers will take the option from action_controller settings.

config.action_controller.default_url_options = .....

BR

Upvotes: 7

Related Questions