在 Rails 3 中从 ActionMailer 模板设置主题?

发布于 2024-12-07 03:51:05 字数 395 浏览 0 评论 0原文

如何从 Rails 3 ActionMailer 模板设置主题?

我想把主题和身体放在一起。

在 Rails 2 中,您可以执行以下操作:(

<% controller.subject = 'Change of subject' %>

来自 http://www.quirkey.com/blog/2008/08/29/actionmailer-changing-the-subject-in-the-template/

How do I set the subject from a Rails 3 ActionMailer template?

I'd like to keep the subject and body together.

In Rails 2 you can do the following:

<% controller.subject = 'Change of subject' %>

(from http://www.quirkey.com/blog/2008/08/29/actionmailer-changing-the-subject-in-the-template/)

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

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

发布评论

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

评论(2

最笨的告白 2024-12-14 03:51:05

http://edgeguides.rubyonrails.org/action_mailer_basics.html

这里说:

class UserMailer < ActionMailer::Base
default :from => "[email protected]"

def welcome_email(user)
  @user = user
  @url  = "http://example.com/login"
  mail(:to => user.email, :subject => "Welcome to My Awesome Site")
  end
end

如果你想要从视图访问它:

http://apidock.com/rails/ActionMailer/Base

如果您需要访问视图中的主题、视图中的收件人或收件人,您可以通过消息对象来实现

 You got a new note from <%= message.from %>!
 <%= truncate(@note.body, 25) %>

:做:

message.subject

http://edgeguides.rubyonrails.org/action_mailer_basics.html

it says here that:

class UserMailer < ActionMailer::Base
default :from => "[email protected]"

def welcome_email(user)
  @user = user
  @url  = "http://example.com/login"
  mail(:to => user.email, :subject => "Welcome to My Awesome Site")
  end
end

If you want to access it from the view:

http://apidock.com/rails/ActionMailer/Base

If you need to access the subject, from or the recipients in the view, you can do that through message object:

 You got a new note from <%= message.from %>!
 <%= truncate(@note.body, 25) %>

So you can do:

message.subject
醉态萌生 2024-12-14 03:51:05

要从电子邮件视图本身设置电子邮件的主题行,您只需将以下内容放在视图文件的开头:

<% message.subject = 'This is my subject line' %>

这适用于 Rails 3 和 4。

To set the subject line of an email from the email view itself you can simply put the following at the beginning of the view file:

<% message.subject = 'This is my subject line' %>

This works for rails 3 and 4.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文