mbleigh-acts-as-taggable-on 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/README +21 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +6 -0
- data/spec/acts_as_taggable_on/taggable_spec.rb +9 -0
- metadata +1 -1
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -76,15 +76,35 @@ end
|
|
76
76
|
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
77
77
|
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
78
78
|
|
79
|
+
# The old way
|
79
80
|
User.find_tagged_with("awesome", :on => :tags) # => [@user]
|
80
81
|
User.find_tagged_with("awesome", :on => :skills) # => []
|
81
82
|
|
83
|
+
# The better way (utilizes named_scope)
|
84
|
+
User.tagged_with("awesome", :on => :tags) # => [@user]
|
85
|
+
User.tagged_with("awesome", :on => :skills) # => []
|
86
|
+
|
82
87
|
@frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
|
83
88
|
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
84
89
|
@frankie.skill_counts
|
85
90
|
|
91
|
+
Finding Tagged Objects
|
92
|
+
======================
|
93
|
+
|
94
|
+
Acts As Taggable On utilizes Rails 2.1's named_scope to create an association
|
95
|
+
for tags. This way you can mix and match to filter down your results, and it
|
96
|
+
also improves compatibility with the will_paginate gem:
|
97
|
+
|
98
|
+
class User < ActiveRecord::Base
|
99
|
+
acts_as_taggable_on :tags
|
100
|
+
named_scope :by_join_date, :order => "created_at DESC"
|
101
|
+
end
|
102
|
+
|
103
|
+
User.tagged_with("awesome").by_date
|
104
|
+
User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
|
105
|
+
|
86
106
|
Relationships
|
87
|
-
|
107
|
+
=============
|
88
108
|
|
89
109
|
You can find objects of the same type based on similar tags on certain contexts.
|
90
110
|
Also, objects will be returned in descending order based on the total number of
|
@@ -79,6 +79,12 @@ module ActiveRecord
|
|
79
79
|
|
80
80
|
before_save :save_cached_tag_list
|
81
81
|
after_save :save_tags
|
82
|
+
|
83
|
+
if respond_to?(:named_scope)
|
84
|
+
named_scope :tagged_with, lambda{ |tags, options|
|
85
|
+
find_options_for_find_tagged_with(tags, options)
|
86
|
+
}
|
87
|
+
end
|
82
88
|
end
|
83
89
|
|
84
90
|
include ActiveRecord::Acts::TaggableOn::InstanceMethods
|
@@ -56,6 +56,15 @@ describe "Taggable" do
|
|
56
56
|
TaggableModel.find_tagged_with("bob", :on => :tags).first.should == @taggable
|
57
57
|
end
|
58
58
|
|
59
|
+
it "should be able to use the tagged_with named scope" do
|
60
|
+
@taggable.skill_list = "ruby, rails, css"
|
61
|
+
@taggable.tag_list = "bob, charlie"
|
62
|
+
@taggable.save
|
63
|
+
TaggableModel.tagged_with("ruby", {}).first.should == @taggable
|
64
|
+
TaggableModel.tagged_with("bob", :on => :skills).first.should_not == @taggable
|
65
|
+
TaggableModel.tagged_with("bob", :on => :tags).first.should == @taggable
|
66
|
+
end
|
67
|
+
|
59
68
|
it "should not care about case" do
|
60
69
|
bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby")
|
61
70
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "Ruby")
|