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

查看:90
本文介绍了主机链接丢失!请为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

我随机得到有时会出现此错误,通常重新启动服务器会解决此问题一段时间,然后再次出现。
我已经在开发和test.rb文件中添加了
config.action_mailer.default_url_options = localhost:3000

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
来访问路线,我读到这可能是我得到这些错误的原因,但是删除这些错误将使我无法访问路由。

该模块用于datatables 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天全站免登陆