Skip to content

Commit c4ee793

Browse files
committed
replaced ActsAsTaggableOnSteroids by ActsAsTaggableOn
1 parent 3c17dcd commit c4ee793

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+135
-1707
lines changed

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem 'rails', '~> 4.2.4'
1010
gem 'sass-rails'
1111

1212
platforms :ruby do
13+
# gem 'pg'
1314
gem 'sqlite3'
1415
end
1516

@@ -44,6 +45,7 @@ gem 'exception_notification', '~> 2.5.2'
4445
gem 'omniauth'
4546
gem 'omniauth-google-oauth2'
4647
gem 'omniauth-openid'
48+
gem 'acts-as-taggable-on', '~> 3.5'
4749

4850
# Bundle gems for the local environment. Make sure to
4951
# put test-only gems in this group so their generators

app/helpers/navigation_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def get_tags_for_published_posts
1717
published_posts = Post.where.not(:published_at => nil)
1818
published_tag_names = published_posts.collect { |post| post.cached_tag_list.split(',') }.flatten.uniq
1919
published_tag_names.each { |tag| tag.strip! }
20-
Tag.where(:name => published_tag_names).sort_by { |tag| tag.taggings.size }.reverse
20+
ActsAsTaggableOn::Tag.where(:name => published_tag_names).sort_by { |tag| tag.taggings.size }.reverse
2121
end
2222
end

app/models/post.rb

+6-17
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def build_for_preview(params)
4444
post.generate_slug
4545
post.set_dates
4646
post.apply_filter
47-
TagList.from(params[:tag_list]).each do |tag|
48-
post.tags << Tag.new(:name => tag)
47+
post.tag_list.each do |tag|
48+
post.tags << ActsAsTaggableOn::Tag.find_or_create_with_like_by_name(tag)
4949
end
5050
post
5151
end
@@ -57,14 +57,11 @@ def find_recent(options = {})
5757
conditions = ['published_at < ?', Time.zone.now]
5858
limit = options[:limit] ||= DEFAULT_LIMIT
5959

60-
options = {
61-
:order => order,
62-
:conditions => conditions,
63-
:limit => limit
64-
}.merge(options)
65-
6660
if tag
67-
find_tagged_with(tag, options)
61+
result = where(conditions)
62+
result = result.tagged_with(tag)
63+
result = result.includes(:tags) if include_tags
64+
result.order(order).limit(limit)
6865
else
6966
result = where(conditions)
7067
result = result.includes(:tags) if include_tags
@@ -136,12 +133,4 @@ def generate_slug
136133
self.slug.slugorize!
137134
end
138135

139-
def tag_list=(value)
140-
value = value.split(',') if value.is_a?(String)
141-
value.map!{ |tag_name| Tag::filter_name(tag_name) }
142-
143-
# TODO: Contribute this back to acts_as_taggable_on_steroids plugin
144-
value = value.join(", ") if value.respond_to?(:join)
145-
super(value)
146-
end
147136
end

app/models/stats.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ def comment_count
88
end
99

1010
def tag_count
11-
Tag.count
11+
ActsAsTaggableOn::Tag.count
1212
end
1313
end

app/models/tag.rb

-43
This file was deleted.

app/models/tagging.rb

-12
This file was deleted.

app/views/admin/posts/_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%= form.inputs do -%>
22
<%= form.input :title -%>
33
<%= form.input :body, :hint => "<a href='http://redcloth.org/textile'>Textile enabled</a>. Use Ctrl+E to switch between preview and edit mode.".html_safe -%>
4-
<%= form.input :tag_list, :as => 'string', :required => false, :hint => 'Comma separated: ruby, rails&hellip;'.html_safe -%>
4+
<%= form.input :tag_list, :input_html => { :value => @post.tag_list.join(', ')}, :as => 'string', :required => false, :hint => 'Comma separated: ruby, rails&hellip;'.html_safe -%>
55
<% end -%>
66
<%= form.inputs do -%>
77
<%= form.input :published_at_natural, :label => 'Published at', :as => 'string', :hint => 'Examples: now, yesterday, 1 hour from now, '.html_safe + link_to("etc".html_safe, "http://chronic.rubyforge.org/") + '. Leave blank for an unpublished draft.' -%>

config/initializers/acts_as_taggable_on_steroids.rb

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class DropOldTaggingTables < ActiveRecord::Migration
2+
def up
3+
if ActiveRecord::Base.connection.table_exists? 'tags'
4+
drop_table 'tags'
5+
end
6+
7+
if ActiveRecord::Base.connection.table_exists? 'taggings'
8+
drop_table 'taggings'
9+
end
10+
11+
if index_exists?(:taggings, 'index_taggings_on_taggable_id_and_taggable_type')
12+
remove_index :taggings, :name => 'index_taggings_on_taggable_id_and_taggable_type'
13+
end
14+
15+
if index_exists?(:taggings, 'index_taggings_on_tag_id')
16+
remove_index :taggings, :name => 'index_taggings_on_tag_id'
17+
end
18+
19+
if index_exists?(:tags, 'index_tags_on_name')
20+
remove_index :tags, :name => 'index_tags_on_name'
21+
end
22+
23+
end
24+
25+
def down
26+
raise ActiveRecord::IrreversibleMigration
27+
end
28+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This migration comes from acts_as_taggable_on_engine (originally 1)
2+
class ActsAsTaggableOnMigration < ActiveRecord::Migration
3+
def self.up
4+
create_table :tags do |t|
5+
t.string :name
6+
end
7+
8+
create_table :taggings do |t|
9+
t.references :tag
10+
11+
# You should make sure that the column created is
12+
# long enough to store the required class names.
13+
t.references :taggable, polymorphic: true
14+
t.references :tagger, polymorphic: true
15+
t.string :taggable_type, null: false
16+
17+
# Limit is created to prevent MySQL error on index
18+
# length for MyISAM table type: http://bit.ly/vgW2Ql
19+
t.string :context, limit: 128
20+
21+
t.datetime :created_at
22+
end
23+
24+
add_index :taggings, :tag_id
25+
add_index :taggings, [:taggable_id, :taggable_type, :context]
26+
end
27+
28+
def self.down
29+
drop_table :taggings
30+
drop_table :tags
31+
end
32+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This migration comes from acts_as_taggable_on_engine (originally 2)
2+
class AddMissingUniqueIndices < ActiveRecord::Migration
3+
def self.up
4+
add_index :tags, :name, unique: true
5+
6+
remove_index :taggings, :tag_id
7+
remove_index :taggings, [:taggable_id, :taggable_type, :context]
8+
add_index :taggings,
9+
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
10+
unique: true, name: 'taggings_idx'
11+
end
12+
13+
def self.down
14+
remove_index :tags, :name
15+
16+
remove_index :taggings, name: 'taggings_idx'
17+
add_index :taggings, :tag_id
18+
add_index :taggings, [:taggable_id, :taggable_type, :context]
19+
end
20+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# This migration comes from acts_as_taggable_on_engine (originally 3)
2+
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
3+
def self.up
4+
add_column :tags, :taggings_count, :integer, default: 0
5+
6+
ActsAsTaggableOn::Tag.reset_column_information
7+
ActsAsTaggableOn::Tag.find_each do |tag|
8+
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
9+
end
10+
end
11+
12+
def self.down
13+
remove_column :tags, :taggings_count
14+
end
15+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This migration comes from acts_as_taggable_on_engine (originally 4)
2+
class AddMissingTaggableIndex < ActiveRecord::Migration
3+
def self.up
4+
add_index :taggings, [:taggable_id, :taggable_type, :context]
5+
end
6+
7+
def self.down
8+
remove_index :taggings, [:taggable_id, :taggable_type, :context]
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This migration comes from acts_as_taggable_on_engine (originally 5)
2+
# This migration is added to circumvent issue #623 and have special characters
3+
# work properly
4+
class ChangeCollationForTagNames < ActiveRecord::Migration
5+
def up
6+
if ActsAsTaggableOn::Utils.using_mysql?
7+
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
8+
end
9+
end
10+
end

db/schema.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20150414113518) do
14+
ActiveRecord::Schema.define(version: 20151218121134) do
1515

1616
create_table "comments", force: true do |t|
1717
t.integer "post_id", null: false
@@ -80,18 +80,22 @@
8080
create_table "taggings", force: true do |t|
8181
t.integer "tag_id"
8282
t.integer "taggable_id"
83+
t.string "taggable_type", null: false
84+
t.integer "tagger_id"
85+
t.string "tagger_type"
86+
t.string "context", limit: 128
8387
t.datetime "created_at"
8488
end
8589

86-
add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id"
87-
add_index "taggings", ["taggable_id"], name: "index_taggings_on_taggable_id_and_taggable_type"
90+
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true, using: :btree
91+
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context", using: :btree
8892

8993
create_table "tags", force: true do |t|
9094
t.string "name"
91-
t.integer "taggings_count", default: 0, null: false
95+
t.integer "taggings_count", default: 0
9296
end
9397

94-
add_index "tags", ["name"], name: "index_tags_on_name"
98+
add_index "tags", ["name"], name: "index_tags_on_name", unique: true, using: :btree
9599

96100
create_table "undo_items", force: true do |t|
97101
t.string "type", null: false

0 commit comments

Comments
 (0)