acts_as_taggable 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README +89 -70
- data/lib/taggable.rb +610 -467
- data/test/acts_as_taggable_test.rb +412 -384
- metadata +26 -39
data/CHANGELOG
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
2.0
|
2
|
+
FEATURE:Added in count_uniq_tagged with - (Patch by Lon Baker)
|
3
|
+
BUGFIX: Fixed typos - (Patch Blair Zajac)
|
4
|
+
FEATURE: clear_tags - clears all tags
|
5
|
+
FEATURE: remove_tag - removes 1 or more tags
|
6
|
+
FEATURE: replace_tag - replaces 1 or more tags with one or more tags
|
7
|
+
BUGFIX: join table now follows the rails convention
|
8
|
+
FEATURE: :tag_class_column_name - allows overriding of the tag name column (Patch Sam Joseph)
|
9
|
+
FEATURE: find_related_tagged now supports :conditions
|
10
|
+
FEATURE: :normalizer - allows the system to standardize the case for all tags - controlled by a Proc you provide
|
data/README
CHANGED
@@ -1,70 +1,89 @@
|
|
1
|
-
= The Acts As Taggable Mixin
|
2
|
-
|
3
|
-
== Installation
|
4
|
-
|
5
|
-
To install or update the gem, simply execute:
|
6
|
-
|
7
|
-
gem install acts_as_taggable
|
8
|
-
|
9
|
-
To use the 'acts_as_taggable' library in your Rails application after installing
|
10
|
-
the gem, add this line at the end of your 'config/environment.rb' file:
|
11
|
-
|
12
|
-
require_gem 'acts_as_taggable'
|
13
|
-
|
14
|
-
== Usage Instructions
|
15
|
-
|
16
|
-
To use the acts_as_taggable mixin with your ActiveRecord objects, you must use
|
17
|
-
a normalized database schema for tagging (also know as folksnomies).
|
18
|
-
|
19
|
-
This means that you must have a table solely for holding tag names. Usually,
|
20
|
-
this table is named 'tags' having at least 2 columns: primary key (usually
|
21
|
-
an autoincrement integer called 'id' - the AR standard for PKs) and a 'name'
|
22
|
-
columns, usually a varchar. You must also have a defined ActiveRecord model
|
23
|
-
class that relates to this table, by default called 'Tag'.
|
24
|
-
|
25
|
-
For associating tags to your objects you also must have join tables that are
|
26
|
-
composed of at least 2 columns: the tags table foreign key (by default 'tag_id')
|
27
|
-
and your taggable object table foreign key.
|
28
|
-
|
29
|
-
If
|
30
|
-
primary key (usually an 'id' column) defined on the join table. If
|
31
|
-
a full join model, you must add a primary key column to the join table. Please
|
32
|
-
see the RDoc documentation on acts_as_taggable macro and the :join_class_name
|
33
|
-
option for the differences between these two approaches.
|
34
|
-
|
35
|
-
For example, suppose you are tagging photos and you hold your photo data thru
|
36
|
-
the Photo model and on the 'photos' table. Your database schema would look
|
37
|
-
something like this (example suited for MySQL):
|
38
|
-
|
39
|
-
CREATE TABLE `tags` (
|
40
|
-
`id` int(11) NOT NULL auto_increment,
|
41
|
-
`name` varchar(255) default NULL,
|
42
|
-
PRIMARY KEY (`id`)
|
43
|
-
)
|
44
|
-
|
45
|
-
CREATE TABLE `
|
46
|
-
`tag_id` int(11) NOT NULL,
|
47
|
-
`photo_id` int(11) NOT NULL
|
48
|
-
)
|
49
|
-
|
50
|
-
CREATE TABLE `photos` (
|
51
|
-
`id` int(11) NOT NULL auto_increment,
|
52
|
-
`title` varchar(255) default NULL,
|
53
|
-
`author_name` varchar(255) default NULL,
|
54
|
-
`image_path` varchar(255) default NULL,
|
55
|
-
PRIMARY KEY (`id`)
|
56
|
-
)
|
57
|
-
|
58
|
-
You would normally define 2 models to relate to these tables:
|
59
|
-
|
60
|
-
class Tag < ActiveRecord::Base
|
61
|
-
end
|
62
|
-
|
63
|
-
class Photo < ActiveRecord::Base
|
64
|
-
acts_as_taggable
|
65
|
-
end
|
66
|
-
|
67
|
-
Now you can easily apply and search for tags on photos in your Rails application.
|
68
|
-
|
69
|
-
This assumes
|
70
|
-
with non-standard naming conventions, please see the proper RDoc documentation.
|
1
|
+
= The Acts As Taggable Mixin
|
2
|
+
|
3
|
+
== Installation
|
4
|
+
|
5
|
+
To install or update the gem, simply execute:
|
6
|
+
|
7
|
+
gem install acts_as_taggable
|
8
|
+
|
9
|
+
To use the 'acts_as_taggable' library in your Rails application after installing
|
10
|
+
the gem, add this line at the end of your 'config/environment.rb' file:
|
11
|
+
|
12
|
+
require_gem 'acts_as_taggable'
|
13
|
+
|
14
|
+
== Usage Instructions
|
15
|
+
|
16
|
+
To use the acts_as_taggable mixin with your ActiveRecord objects, you must use
|
17
|
+
a normalized database schema for tagging (also know as folksnomies).
|
18
|
+
|
19
|
+
This means that you must have a table solely for holding tag names. Usually,
|
20
|
+
this table is named 'tags' having at least 2 columns: primary key (usually
|
21
|
+
an autoincrement integer called 'id' - the AR standard for PKs) and a 'name'
|
22
|
+
columns, usually a varchar. You must also have a defined ActiveRecord model
|
23
|
+
class that relates to this table, by default called 'Tag'.
|
24
|
+
|
25
|
+
For associating tags to your objects you also must have join tables that are
|
26
|
+
composed of at least 2 columns: the tags table foreign key (by default 'tag_id')
|
27
|
+
and your taggable object table foreign key.
|
28
|
+
|
29
|
+
If youre using the simple has_and_belongs_to_many model, you must NOT have a
|
30
|
+
primary key (usually an 'id' column) defined on the join table. If youre using
|
31
|
+
a full join model, you must add a primary key column to the join table. Please
|
32
|
+
see the RDoc documentation on acts_as_taggable macro and the :join_class_name
|
33
|
+
option for the differences between these two approaches.
|
34
|
+
|
35
|
+
For example, suppose you are tagging photos and you hold your photo data thru
|
36
|
+
the Photo model and on the 'photos' table. Your database schema would look
|
37
|
+
something like this (example suited for MySQL):
|
38
|
+
|
39
|
+
CREATE TABLE `tags` (
|
40
|
+
`id` int(11) NOT NULL auto_increment,
|
41
|
+
`name` varchar(255) default NULL,
|
42
|
+
PRIMARY KEY (`id`)
|
43
|
+
)
|
44
|
+
|
45
|
+
CREATE TABLE `photos_tags` (
|
46
|
+
`tag_id` int(11) NOT NULL,
|
47
|
+
`photo_id` int(11) NOT NULL
|
48
|
+
)
|
49
|
+
|
50
|
+
CREATE TABLE `photos` (
|
51
|
+
`id` int(11) NOT NULL auto_increment,
|
52
|
+
`title` varchar(255) default NULL,
|
53
|
+
`author_name` varchar(255) default NULL,
|
54
|
+
`image_path` varchar(255) default NULL,
|
55
|
+
PRIMARY KEY (`id`)
|
56
|
+
)
|
57
|
+
|
58
|
+
You would normally define 2 models to relate to these tables:
|
59
|
+
|
60
|
+
class Tag < ActiveRecord::Base
|
61
|
+
end
|
62
|
+
|
63
|
+
class Photo < ActiveRecord::Base
|
64
|
+
acts_as_taggable
|
65
|
+
end
|
66
|
+
|
67
|
+
Now you can easily apply and search for tags on photos in your Rails application.
|
68
|
+
|
69
|
+
This assumes youre using only default naming conventions. For using the mix-in
|
70
|
+
with non-standard naming conventions, please see the proper RDoc documentation.
|
71
|
+
|
72
|
+
== Upgrading to 2.0
|
73
|
+
|
74
|
+
The new version now uses the Rails standard join table names. In the past it was always prefixed by tags,
|
75
|
+
independent of the alphabetical order.
|
76
|
+
|
77
|
+
If you would like to upgrade without changing your table names, or if you prefer the other style - modify
|
78
|
+
your models as follows
|
79
|
+
|
80
|
+
|
81
|
+
class Photo < ActiveRecord::Base
|
82
|
+
acts_as_taggable
|
83
|
+
end
|
84
|
+
|
85
|
+
becomes
|
86
|
+
|
87
|
+
class Photo < ActiveRecord::Base
|
88
|
+
acts_as_taggable :join_table => "tags_photos"
|
89
|
+
end
|