ActionView::Template::Error: 缺少要链接的主机 [英] ActionView::Template::Error: Missing host to link to

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

问题描述

正如标题所暗示的,当我尝试在邮件模板中使用 link_to 时出现此错误:

As the title implies, I'm getting this error when I try to use link_to in my mailer templates:

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

我试着按照它的说明去做,我还发现了 这篇文章,但我仍然收到错误消息.

I tried to follow it's instructions, and I also found this post, but I'm still getting the error.

我尝试将 config.action_mailer.default_url_options = { host: 'example.com' } 添加到以下每个文件中,但没有一个起作用:

I've tried adding config.action_mailer.default_url_options = { host: 'example.com' } to each of the following files and none of them worked:

/config/environment.rb
/config/application.rb (inside the module for my app)
/config/development.rb (I'm in development mode)

Rails 4 中是否有一些变化使这项工作有所不同?

Has something changed in Rails 4 that makes this work differently?

推荐答案

前几天我遇到了这个问题,这就是最终对我有用的方法:

I ran into this problem the other day and this is what ended up working for me:

Rails.application.routes.default_url_options[:host] = '???'

编辑

这在每个环境文件中 - development.rbtest.rbproduction.rb(如果你有的话,还有更多)每一个都有对应的主机名

This goes in each environment file - development.rb, test.rb and production.rb (and more if you have them) with the corresponding host name in each one

这篇关于ActionView::Template::Error: 缺少要链接的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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