ruby-on-rails - 操作邮件程序中的默认 url 不工作

标签 ruby-on-rails ruby smtp actionmailer mandrill

我正在本地主机上进行测试。这是我的 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

这是 View :

<!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>

我该如何解决这个问题?

最佳答案

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

  verify_other_school_path(@school)

使用

  verify_other_school_url(@school)

  verify_other_school_path(only_path: false, @school)

并阅读this

关于ruby-on-rails - 操作邮件程序中的默认 url 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22842662/

相关文章:

ruby-on-rails - 如何从 Controller 外部访问Rails Controller View 上下文?

ruby-on-rails - 在 "Sign Up"之后填充数据库

ruby-on-rails - 如何对这个哈希数组进行分组?

ruby - 无法在 ubuntu 14.04 lts 上安装 fileutils Rubygem

meteor - 邮件未发送;要启用发送,请设置 MAIL_URL 环境变量

ruby-on-rails - Rails - 播种 HABTM 协会

ruby-on-rails - Ruby:如何从包含模块的类中访问常量

ruby-on-rails - Heroku 在上传 Assets 时忽略 RACK_ENV= staging

python - Python 的 SMTP AUTH 扩展问题

iis - IIS 7 中是否弃用了 SMTP 虚拟服务器?