缺少要链接的主机!请为 Rails 4 提供 :host 参数 [英] Missing host to link to! Please provide the :host parameter, for Rails 4

查看:23
本文介绍了缺少要链接的主机!请为 Rails 4 提供 :host 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

缺少要链接的主机!请提供 :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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆