Rails 3 actionmailer 如何决定使用哪种格式?

发布于 2024-09-30 17:57:56 字数 504 浏览 1 评论 0原文

在文档中,它说,邮件程序操作的行为方式与控制器操作非常相似。 在rails指南中,发送邮件:

UserMailer.welcome_email(@user).deliver

和welcome_email操作看起来像这样:

def welcome_email(user)
  @user = user
  @url = "http://example.com/login"
  mail(:to => user.email, :subject => "Welcome to My Awesome Site") do |format|
   format.html { render 'another_template' }
   format.text { render 'another_template' }
  end 
end 

我不明白的是,welcome_email操作如何决定使用哪种格式(html或文本)?

谢谢!

In documentation it says, that mailer actions behave in very similar fashion as controller actions.
In rails guide, to send mail:

UserMailer.welcome_email(@user).deliver

and welcome_email action looks like this:

def welcome_email(user)
  @user = user
  @url = "http://example.com/login"
  mail(:to => user.email, :subject => "Welcome to My Awesome Site") do |format|
   format.html { render 'another_template' }
   format.text { render 'another_template' }
  end 
end 

what I don't get is, how welcome_email action decides which format to use (html or text)?

Thanks!

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

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

发布评论

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

评论(1

撩心不撩汉 2024-10-07 17:57:56

我相信它将创建一封包含 html 和文本部分的多部分电子邮件。这将允许纯文本客户端使用该部分来渲染它,并且基于 html 的客户端也可以正确渲染它。

Rails 3:http://guides.rubyonrails.org/action_mailer_basics.html

Rails 2:http://guides.rubyonrails.org/v2.3.8/action_mailer_basics.html

I believe it will create a multipart email that includes both html and text parts. This will allow text only clients to render it using that part and html based clients to render it properly too.

Rails 3: http://guides.rubyonrails.org/action_mailer_basics.html

Rails 2: http://guides.rubyonrails.org/v2.3.8/action_mailer_basics.html

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