forked from jhulick/ch-sheets
/
ruby.acts_as_taggable_on.sheet
27 lines (20 loc) · 1.14 KB
/
ruby.acts_as_taggable_on.sheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
script/plugin install git://github.com/mbleigh/acts-as-taggable-on.git
class User < ActiveRecord::Base
acts_as_taggable_on :tags, :skills, :interests, :sports
end
@user = User.new(:name => "Bobby")
@user.tag_list = "awesome, slick, hefty" # this should be familiar
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
@user.skill_list # => ["joking","clowning","boxing"] as TagList
@user.save
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
User.find_tagged_with("awesome") # => [@user]
User.find_tagged_with("joking") # => [@user]
User.find_tagged_with("awesome", :on => :tags) # => [@user]
User.find_tagged_with("awesome", :on => :skills) # => []
@frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
@bobby.skill_counts
@frankie.skill_counts
(http://www.intridea.com/2007/12/4/announcing-acts_as_taggable_on)