在 rails 中将电子邮件路由到 ip 而不是域名

Devise email routing to ip instead of domain name in rails

我正在通过默认设计密码重置说明电子邮件发送密码重置说明。当我单击更改密码时,它会将我路由到本地计算机中的 localhost:3000,但在生产中它会路由到某个 ip。我觉得是我们托管的云服务器,怎么改成域名?

这是设计密码重置说明:

<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></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>

如何更改我是否必须将 url 硬编码到域?因为我们有暂存和生产环境。

我刚刚给出了一般在生产环境中发送电子邮件的快速回答。

在您的特定情况下,您正在寻找将以下代码放入 production.rb:

config.action_mailer.default_url_options = { :host => 'YOUR-APP-NAME.herokuapp.com', :protocol => 'https' }

如果你有多个环境,你会分别配置每个环境,对吗?因此,对于暂存,您将拥有 config/environments/staging.rb 之类的内容并在那里进行配置。

More details on action mailer