我正在使用rails和设计,我正在尝试发送电子邮件,但我在生产和测试环境中得到以下错误,在开发中一切正常:
::的ActionView模板::错误: 缺少主机链接!请提供:host参数,设置default_url_options [:host],或将:only_path设置为true #。/ app/views/devise/mailer/reset_password_instructions.html.erb:9:in`_app_views_devise_mailer_reset_password_instructions_html_erb ___ 200197999_97517150'
我的development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000" }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
test.rb
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = { :host => "localhost:3000" }
production.rb
config.action_mailer.default_url_options = { :host => "mydomain.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
reset_password_instructions.html.erb
<p>Hello, <%= @resource.full_name %>!</p>
<p>You have request a new passord</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token), class: 'btn btn-info' %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
错误在哪里?
答案 0 :(得分:8)
我不确定它是否是拼写错误,但看起来测试和生产的主机定义设置不正确。
test.rb:
config.action_mailer.default_url_options = { :host => "http://loclahost:3000" }
production.rb:
config.action_mailer.default_url_options = { :host => "http:/mydomain.com" }
一旦设置正确,它应该可以正常工作。例如:
test.rb:
config.action_mailer.default_url_options = { :host => "localhost:3000" }
production.rb:
config.action_mailer.default_url_options = { :host => "mydomain.com" }
答案 1 :(得分:2)
最后,我为每个环境文件添加了以下正确的值:
test.rb / development.rb / production.rb
设计3.2.x
Rails 4.1.x
感谢maudulus
# Default Mailer Host
Rails.application.routes.default_url_options[:host] = 'domain.com'
*注意不要从ENV变量加载值,否则会抛出错误。
答案 2 :(得分:1)
我以这种方式解决了问题:https://stackoverflow.com/a/9402816/1759437,在application_controller上设置default_url_options。