问题
Currently for my Rails 3 mailer templates, I need to create an html
and text
version in the views/user_mailer directory
.
Why is that necessary? Why can't rails look at the html
version and automatically format it to a text/plain
version?
回答1:
This is not required. You can simply provide one of those templates. For instance, if you don't need HTML, you can create the TEXT file only.
Likewise, you can provide the HTML template only. Readers will attempts to extract the information. However, if you use HTML, you should provide an alternative TEXT version to make sure the readers won't mess the content of your email.
By the way, Rails doesn't force you to provide both templates.
回答2:
This question seems to be similar to yours and might be helpful to you:
Graceful degradation/progressive enhancement for Action Mailer templates?
Also, here are some direct links to some gems that help to solve this problem of duplication between html and text mailer templates:
- https://github.com/plataformatec/markerb
- https://github.com/Mange/roadie
- https://github.com/fphilipe/premailer-rails3
来源:https://stackoverflow.com/questions/4908446/rails-html-text-usermailer-templates