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.

Subscribing to updates<br />

Great, so now your users will receive multipart emails; their email clients should<br />

attempt to render the HTML part of these first and, if they can’t, then fall back to the<br />

text part. Such is the beauty of email these days.<br />

Now is the time to commit these changes, but not before running your tests by running<br />

rake cucumber:ok spec:<br />

60 scenarios (60 passed)<br />

679 steps (679 passed)<br />

# and<br />

40 examples, 0 failures, 20 pending<br />

Awesome! Everything is still going. Commit this change:<br />

git add .<br />

git commit -m "Send HTML ticket notification emails"<br />

git push<br />

Your ticket notification email will be sent out with two parts: an HTML version and a<br />

text version. This provides a way for email applications of all ages to render your<br />

email. Hopefully, more people will see the HTML version than the text version.<br />

You learned how to generate a mailer and create a mailer method to it, and now<br />

you’re going to move into how you can let people subscribe to receive these emails.<br />

You’re currently only subscribing the ticket’s author to the list of watchers associated<br />

with this ticket, but other people may also wish to be notified of ticket updates. You<br />

can do this in two separate ways: through a watch button and through automatic subscription.<br />

12.2 Subscribing to updates<br />

You’ll provide other users with two ways to stay informed<br />

of ticket updates. The first will be very similar to the<br />

automatic subscription of a user when they create the<br />

ticket, but this time you’ll automatically subscribe users<br />

who comment on a ticket. You’ll reuse the same code that<br />

Figure 12.3 The watch button<br />

you used in the previous section to achieve this, but not in the way you might think.<br />

The second will be a watch button on the ticket page, which will display either<br />

Watch This Ticket or Stop Watching This Ticket, depending on if the user is watching<br />

the ticket or not, as shown in figure 12.3.<br />

We’ll first look at implementing the automatic subscription when a user posts a<br />

comment to a ticket.<br />

12.2.1 Testing comment subscription<br />

You’ll now implement a feature to make users automatically watch a ticket when they<br />

create a comment on it. This is useful because your users will want to keep up-to-date<br />

with tickets that they have commented on. Later on, you’ll implement a way for these<br />

users to opt out.<br />

325

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

Saved successfully!

Ooh no, something went wrong!