Tagger
Installing
-
Install it with
gem install tagger
-
Generate the migration files with
rails generate tagger:install
. -
Finally, run the migrations with
rake db:migrate
.
Usage
Add the method call taggable
to your model.
class Link < ActiveRecord::Base
taggable :scope => :category
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :links
end
@post = Post.first
@category = Category.first
# set tags using the chosen tag separator
@post.tagged_with = "rails, activerecord, models"
# get tags joined with the chosen tag separator
@post.tagged_with
# get all tags as objects
@post.tags
# check if an user tagged this object
@post.tag_owner?(current_user)
# generate a tag cloud
@tags = Tag.cloud(:link, :limit => 100, :scope => @category)
# at the view, call the helper tag_cloud
tag_cloud @tags do |tag_name, css|
<%= link_to tag_name, tag_path(tag_name), :class => css
end
Copyright © 2008 Nando Vieira, released under the MIT license