Acts as Taggable On Tutorial with Rails 5
For more posts in this series, check out my tutorial on Devise Authentication with Rails 5.
Acts as Taggable On is one of my favorite underrated (and awkwardly named) Rails gems. There’s almost always the need to search or organize objects in a Rails application and using tags simplifies the process so much. It also saves developers new to Rails from writing out monstrous Active Record queries. Acts-as-taggable-on is a true work horse, it’s been around since 2010 and has over 8 million downloads to date. Here is a quick getting started guide on using it.
What are tags and why do we use them?
- Tags help users find related information — they allow you to group one or several instances of a model together without having to create a separate category table.
- Tags help when users are not sure what they are looking for — for example, think of Amazon and its related products. Sometimes people who buy toothpaste will also buy tooth brushes. But your site will be more powerful if it can tag the items and suggest things like face wash or body cream.
- Tags allow for a broader ‘category’ label without having to make a standalone table or parent-child-relationship — This means that you can connect several tables without a million foreign keys.