Chapter 11. Tagging
This chapter covers
- Creating a has_and_belongs_to_many relationship between tickets and tags
- Restricting access to tag creation and tag editing
- Adding search functionality for tickets with a given tag or state
In chapter 10 you saw how to give your tickets states (such as “New” or “Open”) so that their progress can be indicated. In this chapter, you’ll see how to give your tickets tags. Tags are useful for grouping similar tickets together, whether by Agile iterations, feature sets, or any other method of grouping. Without tags, you could crudely group tickets together by setting a ticket’s title to something such as “Tag - [name].” This method, however, is messy and difficult to sort through. Having a group of tickets with the same tag will make them much easier to find.
To manage tags, you’ll set up a Tag model, which will have a has_and _belongs_to_many association to the Ticket model. You’ll set up a join table for this association, which is a table that contains foreign key fields for each side of the association. A join table’s sole purpose is to join together the two tables whose keys it has—in this case, the tickets and tags tables. As you move forward in developing this association, note that for all intents and purposes, has_and_belongs _to_many works like a two-way has_many.