Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 268
Raunak Joneja Avatar asked Mar 21 '16 13:03

Raunak Joneja


4 Answers

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.

like image 60
David Avatar answered Oct 24 '22 07:10

David


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" }
like image 28
Rajarshi Das Avatar answered Oct 24 '22 06:10

Rajarshi Das


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' }
like image 22
Ruben Cruz Avatar answered Oct 24 '22 07:10

Ruben Cruz


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

like image 43
Andy Avatar answered Oct 24 '22 07:10

Andy