Rails 3 actionmailer 如何决定使用哪种格式?
在文档中,它说,邮件程序操作的行为方式与控制器操作非常相似。 在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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信它将创建一封包含 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