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.

This chapter covers<br />

� Adding a state-tracking ability to a model<br />

� Using callbacks within Active Record<br />

� Preventing basic form hacking<br />

243<br />

Tracking state<br />

In a ticket-tracking application such as Ticketee, tickets aren’t there to provide<br />

information about a particular problem or suggestion; rather, they’re there to provide<br />

the workflow for it. The general workflow of a ticket is that a user will file it and<br />

it’ll be classified as a “new” ticket. When the developers of the project look at this<br />

ticket and decide to work on it, they’ll switch the state on the ticket to “open” and,<br />

once they’re done, mark it as “resolved.” If a ticket needs more information on it<br />

then they’ll add another state, such as “needs more info.” A ticket could also be a<br />

duplicate of another ticket or it could be something that the developers determine<br />

isn’t worthwhile putting in. In cases such as this, the ticket may be marked as<br />

“duplicate” or “invalid,” respectively.<br />

The point is that tickets have a workflow, and that workflow revolves around<br />

state changes. You’ll allow the admin users of this application to add states, but not<br />

to delete them. The reason for this is if an admin were to delete a state that was

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

Saved successfully!

Ooh no, something went wrong!