Tagliatelle
Installation
Add this line to your application's Gemfile:
gem "tagliatelle"
And then execute:
$ bundle
Generate model classes and migrations:
$ rails generate tagliatelle:install
Review the generated migrations then migrate:
$ rake db:migrate
Usage
Tagliatelle expects two classes to be defined:
class Tag < ActiveRecord::Base
include Tagliatelle::Tag
end
class Tagging < ActiveRecord::Base
include Tagliatelle::Tagging
end
You can add or override behavior to these classes as needed.
Then to make an object taggable:
class Article < ActiveRecord::Base
include Tagliatelle::Taggable
end
To tag an object:
article = Article.first
article.tag_list = "foo, bar"
article.save
To retrieve the tags of an object:
article = Article.first
article.tag_list
To query objects based on tags:
Article.tagged_with(["foo", "bar"])