【问题标题】:default url in action mailer not working动作邮件程序中的默认网址不起作用
【发布时间】:2014-05-15 13:53:04
【问题描述】:

我正在我的本地主机上进行测试。这是我的 development.rb 文件的 action_mailer 部分:

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :user_name => "my_email@email.com,
    :password  => ENV['MANDRILL_API_KEY'],

}

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

这里是 action_mailer 文件:

def confirm_email(user, school, email)
   @user = user
   @school = school
   @email = email
   @url  = 'http://example.com/login'
  mail(to: @email, subject: 'Please confirm your additional school email.')
end

这是视图:

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Hello <%= @user.first_name %></h1>

    <p>
      To confirm your additional school, <%= link_to "click here", verify_other_school_path(@school) %>.
    </p>
    <p>Thanks and have a great day!</p>
  </body>
</html>

电子邮件正在正常工作并发送。唯一的问题是为链接生成的 html 看起来像:

<a href="http://verifyotherschool/4" target="_blank">click here</a>

而不是应有的方式:

<a href="http://localhost:3000/verifyotherschool/4" target="_blank">click here</a>

我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails ruby smtp actionmailer mandrill


    【解决方案1】:

    记住path 是相对的,而url 是绝对的。
    而是

      verify_other_school_path(@school)
    

    使用

      verify_other_school_url(@school)
    

      verify_other_school_path(only_path: false, @school)
    

    并阅读this

    【讨论】:

      猜你喜欢
      • 2017-02-17
      • 1970-01-01
      • 2014-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多