Agile Web Development with Rails 5.1 by Sam Ruby

Agile Web Development with Rails 5.1 by Sam Ruby

Author:Sam Ruby
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
Publisher: Pragmatic Bookshelf


In the preceding section, we created a plain-text email. The view file for our received action was called received.text.erb. This is the standard Rails naming convention. We can also create HTML-formatted emails.

Let’s try this with the order-shipped notification. We don’t need to modify any code—we simply need to create a new template:

rails51/depot_qa/app/views/order_mailer/shipped.html.erb

​ <h3>Pragmatic Order Shipped</h3>

​ <p>

​ This is just to let you know that we've shipped your recent order:

​ </p>

​ <table>

​ <tr><th colspan=​"2"​>Qty</th><th>Description</th></tr>

​ ​<%=​ render @order.line_items ​-%>​

​ </table>

We don’t need to modify the partial, because the existing one will do just fine:

rails51/depot_qa/app/views/line_items/_line_item.html.erb

​ ​<%​ ​if​ line_item == @current_item ​%>​

​ <tr class=​"line-item-highlight"​>

​ ​<%​ ​else​ ​%>​

​ <tr>

​ ​<%​ ​end​ ​%>​

​ <td class=​"quantity"​>​<%=​ line_item.quantity ​%>​</td>

​ <td>​<%=​ line_item.product.title ​%>​</td>

​ <td class=​"price"​>​<%=​ number_to_currency(line_item.total_price) ​%>​</td>

​ </tr>

But for email templates, Rails provides a bit more naming magic. If you create multiple templates with the same name but with different content types embedded in their filenames, Rails will send all of them in one email, arranging the content so that the email client can distinguish each.

This means you’ll want to either update or delete the plain-text template that Rails provided for the shipped notifier.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.