我如何设置邮件主机,以便我可以使用一台用于生产,一台用于开发 Rails

发布于 2024-12-09 11:54:47 字数 878 浏览 0 评论 0原文

我的邮件程序中有以下内容:

#activate board first using a different email?
def welcome_manager(participant)
  @participant = participant
  @user  = participant.user
  @board = participant.board
  @url   = birthday_url(@participant.token, :host => "birthday-greeting.net")
  mail(:to => @user.email, :subject => "Confirmation: #{@board.bp_name.possessive} Happy Birthday Board Created" )
end

它在线使用主机。 但是,当我在开发中时,我想使用 localhost:3000,如下所示:

#activate board first using a different email?
def welcome_manager(participant)
  @participant = participant
  @user  = participant.user
  @board = participant.board
  @url   = birthday_url(@participant.token, :host => "localhost:3000")
  mail(:to => @user.email, :subject => "Confirmation: #{@board.bp_name.possessive} Happy Birthday Board Created" )
end

我该怎么做?

I have the following in my mailer:

#activate board first using a different email?
def welcome_manager(participant)
  @participant = participant
  @user  = participant.user
  @board = participant.board
  @url   = birthday_url(@participant.token, :host => "birthday-greeting.net")
  mail(:to => @user.email, :subject => "Confirmation: #{@board.bp_name.possessive} Happy Birthday Board Created" )
end

Which uses the host online.
However when I am in development I want to use localhost:3000 as follows:

#activate board first using a different email?
def welcome_manager(participant)
  @participant = participant
  @user  = participant.user
  @board = participant.board
  @url   = birthday_url(@participant.token, :host => "localhost:3000")
  mail(:to => @user.email, :subject => "Confirmation: #{@board.bp_name.possessive} Happy Birthday Board Created" )
end

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绻影浮沉 2024-12-16 11:54:47

您应该在相应的 config/environment/development.rbproduction.rb 中设置邮件主机。

但是,如果您确实需要像这样内联执行此操作,只需在 Rails.env 上使用条件即可:

:host => Rails.env == "production" ? "birthday-greeting.org" : "localhost:3000"

You should setup your mail host in the respective config/environment/development.rb and production.rb.

However, if you really need to do it inline like that, just use a conditional on Rails.env:

:host => Rails.env == "production" ? "birthday-greeting.org" : "localhost:3000"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文