缺少要链接的主机!请为 Rails 4 提供 :host 参数 [英] Missing host to link to! Please provide the :host parameter, for Rails 4
问题描述
缺少要链接的主机!请提供 :host 参数,设置default_url_options[:host],或者设置:only_path 为true
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
我当时随机收到这个错误,一般重启服务器可以解决一段时间的问题,然后它又出现了.我已经添加了config.action_mailer.default_url_options = "localhost:3000"
,在 development 和 test.rb 文件中.
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.
另外,我使用了 include Rails.application.routes.url_helpers
在一个模块中访问路由,我读到这可能是我收到这些错误的原因,但删除它会使我无法访问路由.
该模块用于数据表 gem.
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.
推荐答案
对于 Rails 5,使用:
For Rails 5, use:
Rails.application.routes.default_url_options[:host] = "XXX"
您可以将其放在 config/environments/
文件(或任何其他初始化程序)中,或例如config/routes.rb
的开头.
You can put this in a config/environments/
file (or any other initializer), or e.g. at the beginning of config/routes.rb
.
这篇关于缺少要链接的主机!请为 Rails 4 提供 :host 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!