2

我有一个带有设置的 actionmailer:

配置/初始化程序/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而不是。这适用于其他 2 个链接(user_url(@user)将我发送到https//pacific-ravine-3563.herokuapp.com/users/9等)

是因为我错误地设置了 default_url 吗?

4

1 回答 1

1

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

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

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

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

于 2012-11-08T20:33:33.323 回答