acts-as-taggable-on 2.3.3 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -3
- data/Appraisals +7 -0
- data/Gemfile +3 -1
- data/{MIT-LICENSE → LICENSE.md} +1 -1
- data/README.md +303 -0
- data/Rakefile +2 -2
- data/acts-as-taggable-on.gemspec +25 -18
- data/gemfiles/rails_3.gemfile +8 -0
- data/gemfiles/rails_4.gemfile +8 -0
- data/lib/acts-as-taggable-on.rb +5 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb +2 -2
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +64 -7
- data/lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb +34 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +86 -55
- data/lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb +3 -3
- data/lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb +24 -15
- data/lib/acts_as_taggable_on/acts_as_taggable_on/related.rb +32 -21
- data/lib/acts_as_taggable_on/tag.rb +37 -15
- data/lib/acts_as_taggable_on/tag_list.rb +2 -2
- data/lib/acts_as_taggable_on/taggable.rb +10 -7
- data/lib/acts_as_taggable_on/tagger.rb +12 -3
- data/lib/acts_as_taggable_on/tagging.rb +2 -2
- data/lib/acts_as_taggable_on/tags_helper.rb +0 -2
- data/lib/{acts-as-taggable-on → acts_as_taggable_on}/version.rb +1 -1
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +1 -183
- data/spec/acts_as_taggable_on/acts_as_tagger_spec.rb +8 -8
- data/spec/acts_as_taggable_on/related_spec.rb +143 -0
- data/spec/acts_as_taggable_on/single_table_inheritance_spec.rb +187 -0
- data/spec/acts_as_taggable_on/tag_list_spec.rb +4 -4
- data/spec/acts_as_taggable_on/tag_spec.rb +61 -3
- data/spec/acts_as_taggable_on/taggable_spec.rb +178 -98
- data/spec/acts_as_taggable_on/tagger_spec.rb +32 -33
- data/spec/acts_as_taggable_on/tagging_spec.rb +1 -1
- data/spec/acts_as_taggable_on/tags_helper_spec.rb +2 -2
- data/spec/acts_as_taggable_on/utils_spec.rb +2 -2
- data/spec/models.rb +8 -2
- data/spec/schema.rb +1 -1
- data/spec/spec_helper.rb +7 -4
- metadata +101 -56
- data/CHANGELOG +0 -35
- data/README.rdoc +0 -244
- data/rails/init.rb +0 -1
- data/uninstall.rb +0 -1
data/spec/spec_helper.rb
CHANGED
@@ -58,15 +58,18 @@ if File.exists?(database_yml)
|
|
58
58
|
ActiveRecord::Base.establish_connection(config)
|
59
59
|
end
|
60
60
|
|
61
|
-
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
61
|
+
logger = ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
62
62
|
ActiveRecord::Base.default_timezone = :utc
|
63
63
|
|
64
|
-
|
64
|
+
begin
|
65
|
+
old_logger_level, logger.level = logger.level, ::Logger::ERROR
|
65
66
|
ActiveRecord::Migration.verbose = false
|
66
67
|
|
67
68
|
load(File.dirname(__FILE__) + '/schema.rb')
|
68
69
|
load(File.dirname(__FILE__) + '/models.rb')
|
69
|
-
|
70
|
+
ensure
|
71
|
+
logger.level = old_logger_level
|
72
|
+
end
|
70
73
|
|
71
74
|
else
|
72
75
|
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
@@ -74,7 +77,7 @@ end
|
|
74
77
|
|
75
78
|
def clean_database!
|
76
79
|
models = [ActsAsTaggableOn::Tag, ActsAsTaggableOn::Tagging, TaggableModel, OtherTaggableModel, InheritingTaggableModel,
|
77
|
-
AlteredInheritingTaggableModel,
|
80
|
+
AlteredInheritingTaggableModel, User, UntaggableModel, OrderedTaggableModel]
|
78
81
|
models.each do |model|
|
79
82
|
ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
|
80
83
|
end
|
metadata
CHANGED
@@ -1,107 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts-as-taggable-on
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
5
|
-
prerelease:
|
4
|
+
version: 2.4.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Bleigh
|
8
|
+
- Joost Baaij
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement:
|
17
|
-
none: false
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3'
|
21
|
+
- - <
|
20
22
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
23
|
+
version: '5'
|
22
24
|
type: :runtime
|
23
25
|
prerelease: false
|
24
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '3'
|
31
|
+
- - <
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec-rails
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.13.0
|
25
48
|
- !ruby/object:Gem::Dependency
|
26
49
|
name: rspec
|
27
|
-
requirement:
|
28
|
-
none: false
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
29
51
|
requirements:
|
30
52
|
- - ~>
|
31
53
|
- !ruby/object:Gem::Version
|
32
54
|
version: '2.6'
|
33
55
|
type: :development
|
34
56
|
prerelease: false
|
35
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
36
62
|
- !ruby/object:Gem::Dependency
|
37
63
|
name: ammeter
|
38
|
-
requirement:
|
39
|
-
none: false
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
40
65
|
requirements:
|
41
|
-
- -
|
66
|
+
- - '>='
|
42
67
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0
|
68
|
+
version: '0'
|
44
69
|
type: :development
|
45
70
|
prerelease: false
|
46
|
-
version_requirements:
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
47
76
|
- !ruby/object:Gem::Dependency
|
48
77
|
name: sqlite3
|
49
|
-
requirement:
|
50
|
-
none: false
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - '>='
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
83
|
type: :development
|
56
84
|
prerelease: false
|
57
|
-
version_requirements:
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
58
90
|
- !ruby/object:Gem::Dependency
|
59
91
|
name: mysql2
|
60
|
-
requirement:
|
61
|
-
none: false
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
62
93
|
requirements:
|
63
94
|
- - ~>
|
64
95
|
- !ruby/object:Gem::Version
|
65
96
|
version: 0.3.7
|
66
97
|
type: :development
|
67
98
|
prerelease: false
|
68
|
-
version_requirements:
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.7
|
69
104
|
- !ruby/object:Gem::Dependency
|
70
105
|
name: pg
|
71
|
-
requirement:
|
72
|
-
none: false
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
73
107
|
requirements:
|
74
|
-
- -
|
108
|
+
- - '>='
|
75
109
|
- !ruby/object:Gem::Version
|
76
110
|
version: '0'
|
77
111
|
type: :development
|
78
112
|
prerelease: false
|
79
|
-
version_requirements:
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
80
118
|
- !ruby/object:Gem::Dependency
|
81
119
|
name: guard
|
82
|
-
requirement:
|
83
|
-
none: false
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
84
121
|
requirements:
|
85
|
-
- -
|
122
|
+
- - '>='
|
86
123
|
- !ruby/object:Gem::Version
|
87
124
|
version: '0'
|
88
125
|
type: :development
|
89
126
|
prerelease: false
|
90
|
-
version_requirements:
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
91
132
|
- !ruby/object:Gem::Dependency
|
92
133
|
name: guard-rspec
|
93
|
-
requirement:
|
94
|
-
none: false
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
95
135
|
requirements:
|
96
|
-
- -
|
136
|
+
- - '>='
|
97
137
|
- !ruby/object:Gem::Version
|
98
138
|
version: '0'
|
99
139
|
type: :development
|
100
140
|
prerelease: false
|
101
|
-
version_requirements:
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
102
146
|
description: With ActsAsTaggableOn, you can tag a single model on several contexts,
|
103
147
|
such as skills, interests, and awards. It also provides other advanced functionality.
|
104
|
-
email:
|
148
|
+
email:
|
149
|
+
- michael@intridea.com
|
150
|
+
- joost@spacebabies.nl
|
105
151
|
executables: []
|
106
152
|
extensions: []
|
107
153
|
extra_rdoc_files: []
|
@@ -109,17 +155,19 @@ files:
|
|
109
155
|
- .gitignore
|
110
156
|
- .rspec
|
111
157
|
- .travis.yml
|
112
|
-
-
|
158
|
+
- Appraisals
|
113
159
|
- Gemfile
|
114
160
|
- Guardfile
|
115
|
-
-
|
116
|
-
- README.
|
161
|
+
- LICENSE.md
|
162
|
+
- README.md
|
117
163
|
- Rakefile
|
118
164
|
- acts-as-taggable-on.gemspec
|
165
|
+
- gemfiles/rails_3.gemfile
|
166
|
+
- gemfiles/rails_4.gemfile
|
119
167
|
- lib/acts-as-taggable-on.rb
|
120
|
-
- lib/acts-as-taggable-on/version.rb
|
121
168
|
- lib/acts_as_taggable_on/acts_as_taggable_on/cache.rb
|
122
169
|
- lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
|
170
|
+
- lib/acts_as_taggable_on/acts_as_taggable_on/compatibility.rb
|
123
171
|
- lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
|
124
172
|
- lib/acts_as_taggable_on/acts_as_taggable_on/dirty.rb
|
125
173
|
- lib/acts_as_taggable_on/acts_as_taggable_on/ownership.rb
|
@@ -131,11 +179,13 @@ files:
|
|
131
179
|
- lib/acts_as_taggable_on/tagging.rb
|
132
180
|
- lib/acts_as_taggable_on/tags_helper.rb
|
133
181
|
- lib/acts_as_taggable_on/utils.rb
|
182
|
+
- lib/acts_as_taggable_on/version.rb
|
134
183
|
- lib/generators/acts_as_taggable_on/migration/migration_generator.rb
|
135
184
|
- lib/generators/acts_as_taggable_on/migration/templates/active_record/migration.rb
|
136
|
-
- rails/init.rb
|
137
185
|
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
138
186
|
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
187
|
+
- spec/acts_as_taggable_on/related_spec.rb
|
188
|
+
- spec/acts_as_taggable_on/single_table_inheritance_spec.rb
|
139
189
|
- spec/acts_as_taggable_on/tag_list_spec.rb
|
140
190
|
- spec/acts_as_taggable_on/tag_spec.rb
|
141
191
|
- spec/acts_as_taggable_on/taggable_spec.rb
|
@@ -149,40 +199,35 @@ files:
|
|
149
199
|
- spec/models.rb
|
150
200
|
- spec/schema.rb
|
151
201
|
- spec/spec_helper.rb
|
152
|
-
|
153
|
-
|
154
|
-
|
202
|
+
homepage: https://github.com/mbleigh/acts-as-taggable-on
|
203
|
+
licenses:
|
204
|
+
- MIT
|
205
|
+
metadata: {}
|
155
206
|
post_install_message:
|
156
207
|
rdoc_options: []
|
157
208
|
require_paths:
|
158
209
|
- lib
|
159
210
|
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
-
none: false
|
161
211
|
requirements:
|
162
|
-
- -
|
212
|
+
- - '>='
|
163
213
|
- !ruby/object:Gem::Version
|
164
214
|
version: '0'
|
165
|
-
segments:
|
166
|
-
- 0
|
167
|
-
hash: -1816807933576177649
|
168
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
216
|
requirements:
|
171
|
-
- -
|
217
|
+
- - '>='
|
172
218
|
- !ruby/object:Gem::Version
|
173
219
|
version: '0'
|
174
|
-
segments:
|
175
|
-
- 0
|
176
|
-
hash: -1816807933576177649
|
177
220
|
requirements: []
|
178
221
|
rubyforge_project:
|
179
|
-
rubygems_version:
|
222
|
+
rubygems_version: 2.0.0
|
180
223
|
signing_key:
|
181
|
-
specification_version:
|
224
|
+
specification_version: 4
|
182
225
|
summary: Advanced tagging for Rails.
|
183
226
|
test_files:
|
184
227
|
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
185
228
|
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
229
|
+
- spec/acts_as_taggable_on/related_spec.rb
|
230
|
+
- spec/acts_as_taggable_on/single_table_inheritance_spec.rb
|
186
231
|
- spec/acts_as_taggable_on/tag_list_spec.rb
|
187
232
|
- spec/acts_as_taggable_on/tag_spec.rb
|
188
233
|
- spec/acts_as_taggable_on/taggable_spec.rb
|
data/CHANGELOG
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
== 2011-08-21
|
2
|
-
* escape _ and % for mysql and postgres (@tilsammans)
|
3
|
-
* Now depends on mysql2 gem
|
4
|
-
* tagged_with :any is chainable now (@jeffreyiacono)
|
5
|
-
* tagged_with(nil) returns scoped object
|
6
|
-
* Case-insensitivity for TaggedModel.tagged_with for PostgreSQL database
|
7
|
-
* tagged_with(' ') returns scoped object
|
8
|
-
* remove warning for rails 3.1 about class_inheritable_attribute
|
9
|
-
* use ActiveRecord migration_number to avoid clashs (@atd)
|
10
|
-
|
11
|
-
== 2010-02-17
|
12
|
-
* Converted the plugin to be compatible with Rails3
|
13
|
-
|
14
|
-
== 2009-12-02
|
15
|
-
|
16
|
-
* PostgreSQL is now supported (via morgoth)
|
17
|
-
|
18
|
-
== 2008-07-17
|
19
|
-
|
20
|
-
* Can now use a named_scope to find tags!
|
21
|
-
|
22
|
-
== 2008-06-23
|
23
|
-
|
24
|
-
* Can now find related objects of another class (tristanzdunn)
|
25
|
-
* Removed extraneous down migration cruft (azabaj)
|
26
|
-
|
27
|
-
== 2008-06-09
|
28
|
-
|
29
|
-
* Added support for Single Table Inheritance
|
30
|
-
* Adding gemspec and rails/init.rb for gemified plugin
|
31
|
-
|
32
|
-
== 2007-12-12
|
33
|
-
|
34
|
-
* Added ability to use dynamic tag contexts
|
35
|
-
* Fixed missing migration generator
|
data/README.rdoc
DELETED
@@ -1,244 +0,0 @@
|
|
1
|
-
= ActsAsTaggableOn
|
2
|
-
{<img src="https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.png" />}[http://travis-ci.org/mbleigh/acts-as-taggable-on]
|
3
|
-
|
4
|
-
This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
|
5
|
-
It has evolved substantially since that point, but all credit goes to him for the
|
6
|
-
initial tagging functionality that so many people have used.
|
7
|
-
|
8
|
-
For instance, in a social network, a user might have tags that are called skills,
|
9
|
-
interests, sports, and more. There is no real way to differentiate between tags and
|
10
|
-
so an implementation of this type is not possible with acts as taggable on steroids.
|
11
|
-
|
12
|
-
Enter Acts as Taggable On. Rather than tying functionality to a specific keyword
|
13
|
-
(namely "tags"), acts as taggable on allows you to specify an arbitrary number of
|
14
|
-
tag "contexts" that can be used locally or in combination in the same way steroids
|
15
|
-
was used.
|
16
|
-
|
17
|
-
== Installation
|
18
|
-
|
19
|
-
=== Rails 2.x
|
20
|
-
|
21
|
-
Not supported any more! It is time for update guys.
|
22
|
-
|
23
|
-
=== Rails 3.x
|
24
|
-
|
25
|
-
To use it, add it to your Gemfile:
|
26
|
-
|
27
|
-
gem 'acts-as-taggable-on', '~> 2.3.1'
|
28
|
-
|
29
|
-
==== Post Installation
|
30
|
-
|
31
|
-
1. rails generate acts_as_taggable_on:migration
|
32
|
-
2. rake db:migrate
|
33
|
-
|
34
|
-
== Testing
|
35
|
-
|
36
|
-
Acts As Taggable On uses RSpec for its test coverage. Inside the gem
|
37
|
-
directory, you can run the specs for RoR 3.x with:
|
38
|
-
|
39
|
-
rake spec
|
40
|
-
|
41
|
-
== Usage
|
42
|
-
|
43
|
-
class User < ActiveRecord::Base
|
44
|
-
# Alias for <tt>acts_as_taggable_on :tags</tt>:
|
45
|
-
acts_as_taggable
|
46
|
-
acts_as_taggable_on :skills, :interests
|
47
|
-
end
|
48
|
-
|
49
|
-
@user = User.new(:name => "Bobby")
|
50
|
-
@user.tag_list = "awesome, slick, hefty" # this should be familiar
|
51
|
-
@user.skill_list = "joking, clowning, boxing" # but you can do it for any context!
|
52
|
-
@user.skill_list # => ["joking","clowning","boxing"] as TagList
|
53
|
-
@user.save
|
54
|
-
|
55
|
-
@user.tags # => [<Tag name:"awesome">,<Tag name:"slick">,<Tag name:"hefty">]
|
56
|
-
@user.skills # => [<Tag name:"joking">,<Tag name:"clowning">,<Tag name:"boxing">]
|
57
|
-
|
58
|
-
@frankie = User.create(:name => "Frankie", :skill_list => "joking, flying, eating")
|
59
|
-
User.skill_counts # => [<Tag name="joking" count=2>,<Tag name="clowning" count=1>...]
|
60
|
-
@frankie.skill_counts
|
61
|
-
|
62
|
-
To preserve the order in which tags are created use acts_as_ordered_taggable:
|
63
|
-
|
64
|
-
class User < ActiveRecord::Base
|
65
|
-
# Alias for <tt>acts_as_ordered_taggable_on :tags</tt>:
|
66
|
-
acts_as_ordered_taggable
|
67
|
-
acts_as_ordered_taggable_on :skills, :interests
|
68
|
-
end
|
69
|
-
|
70
|
-
@user = User.new(:name => "Bobby")
|
71
|
-
@user.tag_list = "east, south"
|
72
|
-
@user.save
|
73
|
-
|
74
|
-
@user.tag_list = "north, east, south, west"
|
75
|
-
@user.save
|
76
|
-
|
77
|
-
@user.reload
|
78
|
-
@user.tag_list # => ["north", "east", "south", "west"]
|
79
|
-
|
80
|
-
|
81
|
-
=== Finding Tagged Objects
|
82
|
-
|
83
|
-
Acts As Taggable On utilizes named_scopes to create an association for tags.
|
84
|
-
This way you can mix and match to filter down your results, and it also improves
|
85
|
-
compatibility with the will_paginate gem:
|
86
|
-
|
87
|
-
class User < ActiveRecord::Base
|
88
|
-
acts_as_taggable_on :tags, :skills
|
89
|
-
scope :by_join_date, order("created_at DESC")
|
90
|
-
end
|
91
|
-
|
92
|
-
User.tagged_with("awesome").by_date
|
93
|
-
User.tagged_with("awesome").by_date.paginate(:page => params[:page], :per_page => 20)
|
94
|
-
|
95
|
-
# Find a user with matching all tags, not just one
|
96
|
-
User.tagged_with(["awesome", "cool"], :match_all => true)
|
97
|
-
|
98
|
-
# Find a user with any of the tags:
|
99
|
-
User.tagged_with(["awesome", "cool"], :any => true)
|
100
|
-
|
101
|
-
# Find a user that not tags with awesome or cool:
|
102
|
-
User.tagged_with(["awesome", "cool"], :exclude => true)
|
103
|
-
|
104
|
-
# Find a user with any of tags based on context:
|
105
|
-
User.tagged_with(['awesome, cool'], :on => :tags, :any => true).tagged_with(['smart', 'shy'], :on => :skills, :any => true)
|
106
|
-
|
107
|
-
You can also use :wild => true option along with :any or :exclude option. It will looking for %awesome% and %cool% in sql.
|
108
|
-
|
109
|
-
Tip: User.tagged_with([]) or '' will return [], but not all records.
|
110
|
-
|
111
|
-
=== Relationships
|
112
|
-
|
113
|
-
You can find objects of the same type based on similar tags on certain contexts.
|
114
|
-
Also, objects will be returned in descending order based on the total number of
|
115
|
-
matched tags.
|
116
|
-
|
117
|
-
@bobby = User.find_by_name("Bobby")
|
118
|
-
@bobby.skill_list # => ["jogging", "diving"]
|
119
|
-
|
120
|
-
@frankie = User.find_by_name("Frankie")
|
121
|
-
@frankie.skill_list # => ["hacking"]
|
122
|
-
|
123
|
-
@tom = User.find_by_name("Tom")
|
124
|
-
@tom.skill_list # => ["hacking", "jogging", "diving"]
|
125
|
-
|
126
|
-
@tom.find_related_skills # => [<User name="Bobby">,<User name="Frankie">]
|
127
|
-
@bobby.find_related_skills # => [<User name="Tom">]
|
128
|
-
@frankie.find_related_skills # => [<User name="Tom">]
|
129
|
-
|
130
|
-
=== Dynamic Tag Contexts
|
131
|
-
|
132
|
-
In addition to the generated tag contexts in the definition, it is also possible
|
133
|
-
to allow for dynamic tag contexts (this could be user generated tag contexts!)
|
134
|
-
|
135
|
-
@user = User.new(:name => "Bobby")
|
136
|
-
@user.set_tag_list_on(:customs, "same, as, tag, list")
|
137
|
-
@user.tag_list_on(:customs) # => ["same","as","tag","list"]
|
138
|
-
@user.save
|
139
|
-
@user.tags_on(:customs) # => [<Tag name='same'>,...]
|
140
|
-
@user.tag_counts_on(:customs)
|
141
|
-
User.tagged_with("same", :on => :customs) # => [@user]
|
142
|
-
|
143
|
-
=== Tag Ownership
|
144
|
-
|
145
|
-
Tags can have owners:
|
146
|
-
|
147
|
-
class User < ActiveRecord::Base
|
148
|
-
acts_as_tagger
|
149
|
-
end
|
150
|
-
|
151
|
-
class Photo < ActiveRecord::Base
|
152
|
-
acts_as_taggable_on :locations
|
153
|
-
end
|
154
|
-
|
155
|
-
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations)
|
156
|
-
@some_user.owned_taggings
|
157
|
-
@some_user.owned_tags
|
158
|
-
@some_photo.locations_from(@some_user) # => ["paris", "normandy"]
|
159
|
-
@some_photo.owner_tags_on(@some_user, :locations) # => [#<ActsAsTaggableOn::Tag id: 1, name: "paris">...]
|
160
|
-
@some_photo.owner_tags_on(nil, :locations) # => Ownerships equivalent to saying @some_photo.locations
|
161
|
-
@some_user.tag(@some_photo, :with => "paris, normandy", :on => :locations, :skip_save => true) #won't save @some_photo object
|
162
|
-
|
163
|
-
=== Dirty objects
|
164
|
-
|
165
|
-
@bobby = User.find_by_name("Bobby")
|
166
|
-
@bobby.skill_list # => ["jogging", "diving"]
|
167
|
-
|
168
|
-
@boddy.skill_list_changed? #=> false
|
169
|
-
@boddy.changes #=> {}
|
170
|
-
|
171
|
-
@bobby.skill_list = "swimming"
|
172
|
-
@bobby.changes.should == {"skill_list"=>["jogging, diving", ["swimming"]]}
|
173
|
-
@boddy.skill_list_changed? #=> true
|
174
|
-
|
175
|
-
@bobby.skill_list_change.should == ["jogging, diving", ["swimming"]]
|
176
|
-
|
177
|
-
=== Tag cloud calculations
|
178
|
-
|
179
|
-
To construct tag clouds, the frequency of each tag needs to be calculated.
|
180
|
-
Because we specified +acts_as_taggable_on+ on the <tt>User</tt> class, we can
|
181
|
-
get a calculation of all the tag counts by using <tt>User.tag_counts_on(:customs)</tt>. But what if we wanted a tag count for
|
182
|
-
an single user's posts? To achieve this we call tag_counts on the association:
|
183
|
-
|
184
|
-
User.find(:first).posts.tag_counts_on(:tags)
|
185
|
-
|
186
|
-
A helper is included to assist with generating tag clouds.
|
187
|
-
|
188
|
-
Here is an example that generates a tag cloud.
|
189
|
-
|
190
|
-
Helper:
|
191
|
-
|
192
|
-
module PostsHelper
|
193
|
-
include ActsAsTaggableOn::TagsHelper
|
194
|
-
end
|
195
|
-
|
196
|
-
Controller:
|
197
|
-
|
198
|
-
class PostController < ApplicationController
|
199
|
-
def tag_cloud
|
200
|
-
@tags = Post.tag_counts_on(:tags)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
View:
|
205
|
-
|
206
|
-
<% tag_cloud(@tags, %w(css1 css2 css3 css4)) do |tag, css_class| %>
|
207
|
-
<%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %>
|
208
|
-
<% end %>
|
209
|
-
|
210
|
-
CSS:
|
211
|
-
|
212
|
-
.css1 { font-size: 1.0em; }
|
213
|
-
.css2 { font-size: 1.2em; }
|
214
|
-
.css3 { font-size: 1.4em; }
|
215
|
-
.css4 { font-size: 1.6em; }
|
216
|
-
|
217
|
-
== Configuration
|
218
|
-
|
219
|
-
If you would like to remove unused tag objects after removing taggings, add
|
220
|
-
|
221
|
-
ActsAsTaggableOn.remove_unused_tags = true
|
222
|
-
|
223
|
-
If you want force tags to be saved downcased:
|
224
|
-
|
225
|
-
ActsAsTaggableOn.force_lowercase = true
|
226
|
-
|
227
|
-
If you want tags to be saved parametrized (you can redefine to_param as well):
|
228
|
-
|
229
|
-
ActsAsTaggableOn.force_parameterize = true
|
230
|
-
|
231
|
-
|
232
|
-
== Contributors
|
233
|
-
|
234
|
-
We have a long list of valued contributors. {Check them all}[https://github.com/mbleigh/acts-as-taggable-on/contributors]
|
235
|
-
|
236
|
-
== Maintainers
|
237
|
-
|
238
|
-
* Artem Kramarenko (artemk)
|
239
|
-
|
240
|
-
== Author
|
241
|
-
|
242
|
-
* Michael Bleigh
|
243
|
-
|
244
|
-
Copyright (c) 2007-2011 Michael Bleigh (http://mbleigh.com/) and Intridea Inc. (http://intridea.com/), released under the MIT license
|
data/rails/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'acts-as-taggable-on'
|
data/uninstall.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Uninstall hook code here
|