Rails:ActionMailer创建故障链接https // link.com而不是https://link.com



我有一个具有设置的动作仪:

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :user_name            => "cool@gmail.com",
  :password             => "cool",
  :authentication       => "plain",
  :enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "https://pacific-ravine-3563.herokuapp.com/"

创建用户时会发出电子邮件。但是,我检查了发送的电子邮件,链接不起作用。这是电子邮件的模板:

Dear <%= @user.name %>,
<p>
    Welcome to Pholder! Get started by finding and inviting <%= link_to "friends", users_url %> so that you can exclusively upload and view pictures with each other.
</p>
<p>
    <%= link_to "View profile", user_url(@user) %>
    <%= link_to "Edit profile", edit_user_url(@user) %>
</p>
<p>
    Sincerely, <br>
    Pholder Staff
</p>

当我检查实际电子邮件时:

Dear Ellen,
Welcome to Pholder! Get started by finding and inviting friends so that you can exclusively upload and view pictures with each other.
View profile Edit profile
Sincerely,
Pholder Staff 

这些链接都没有工作。应该将我发送到users_url的第一个链接将我发送到:https//pacific-ravine-3563.herokuapp.com/users。这是针对其他两个链接(user_url(@user)将我发送到https//pacific-ravine-3563.herokuapp.com/users/9等)

是因为我设置了default_url错误?

尝试以这种方式使用配置:

config.action_mailer.default_url_options = { :protocol => 'https', :host => 'pacific-ravine-3563.herokuapp.com' }

而不是设置您当前正在执行的方式。

如果它没有生成绝对URL,则必须设置:only_path => false,但这只是使用文档中的url_for时发生的行为。

最新更新