27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

320 CHAPTER 12 Sending email<br />

the email body checking line in your scenario and rerun your feature. You should see<br />

the following:<br />

Date: [date]<br />

From: ticketee@gmail.com<br />

To: alice@ticketee.com<br />

Message-ID: [message_id]@[you].mail<br />

Mime-Version: 1.0<br />

Content-Type: text/plain;<br />

charset=UTF-8<br />

Content-Transfer-Encoding: 7bit<br />

This is a raw version of the email that alice@ticketee.com will receive when<br />

bob@ticketee.com updates the ticket. As you can see from this raw version, there’s<br />

nothing else to this email, and therefore there’s no content that will be displayed. To<br />

make this final step pass, you must define some content for your email, which you<br />

can do by defining a template.<br />

12.1.5 An Action Mailer template<br />

Templates for Action Mailer classes go in app/views because they serve an identical purpose<br />

as the controller views: they display a final, dynamic result to the users. Once you<br />

have this template in place, the plain-text email a user receives will look like figure 12.1.<br />

As shown in the figure, you need to mention who updated the ticket, what they<br />

updated it with, and provide a link to the ticket. Let’s put the template for your<br />

comment_updated method at app/views/notifier/comment_updated.text.erb, as shown<br />

in the following listing.<br />

Listing 12.3 app/views/notifier/comment_updated.text.erb<br />

Hello!<br />

has just updated the<br />

ticket for<br />

. They wrote:<br />

<br />

You can view this ticket on line by going to:<br />

<br />

Wait, hold on! text.erb? Yes! This is the template for the plain-text version of this<br />

email, after all. Remember, the format of a view in Rails is the first part of the file<br />

extension, with the latter part being the actual file type. Because you’re sending a textonly<br />

email, you use the text format here. A little further down the email road, you’ll<br />

look at how you can send out HTML emails too.<br />

Figure 12.1<br />

Your first email

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!