configures act_as_taggable [#8]

This commit is contained in:
rgarcia
2015-07-18 17:23:00 +02:00
parent 1f725a2c51
commit 6adedf45b8
7 changed files with 62 additions and 2 deletions

View File

@@ -31,7 +31,7 @@ gem 'devise'
# Use Capistrano for deployment # Use Capistrano for deployment
# gem 'capistrano-rails', group: :development # gem 'capistrano-rails', group: :development
gem 'acts-as-taggable-on'
gem "responders" gem "responders"
gem 'foundation-rails' gem 'foundation-rails'

View File

@@ -36,6 +36,8 @@ GEM
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
acts-as-taggable-on (3.5.0)
activerecord (>= 3.2, < 5)
arel (6.0.2) arel (6.0.2)
bcrypt (3.1.10) bcrypt (3.1.10)
binding_of_caller (0.7.2) binding_of_caller (0.7.2)
@@ -188,6 +190,7 @@ PLATFORMS
ruby ruby
DEPENDENCIES DEPENDENCIES
acts-as-taggable-on
byebug byebug
capybara capybara
coffee-rails (~> 4.1.0) coffee-rails (~> 4.1.0)

View File

@@ -1,4 +1,5 @@
class Debate < ActiveRecord::Base class Debate < ActiveRecord::Base
acts_as_taggable
belongs_to :author, class_name: 'User', foreign_key: 'author_id' belongs_to :author, class_name: 'User', foreign_key: 'author_id'
validates :title, presence: true validates :title, presence: true

View File

@@ -0,0 +1 @@
ActsAsTaggableOn.delimiter = ','

View File

@@ -0,0 +1,25 @@
# This migration comes from acts_as_taggable_on_engine (originally 1)
class ActsAsTaggableOnMigration < ActiveRecord::Migration
def self.up
create_table :tags do |t|
t.string :name
end
create_table :taggings do |t|
t.references :tag
t.references :taggable, polymorphic: true
t.references :tagger, polymorphic: true
t.string :context, limit: 128
t.datetime :created_at
end
add_index :tags, :name, unique: true
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type, :context]
end
def self.down
drop_table :taggings
drop_table :tags
end
end

View File

@@ -0,0 +1,10 @@
# This migration comes from acts_as_taggable_on_engine (originally 3)
class AddTaggingsCounterCacheToTags < ActiveRecord::Migration
def self.up
add_column :tags, :taggings_count, :integer, default: 0
end
def self.down
remove_column :tags, :taggings_count
end
end

View File

@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150717164054) do ActiveRecord::Schema.define(version: 20150718075337) do
create_table "debates", force: :cascade do |t| create_table "debates", force: :cascade do |t|
t.string "title" t.string "title"
@@ -21,6 +21,26 @@ ActiveRecord::Schema.define(version: 20150717164054) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
end end
create_table "taggings", force: :cascade do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id"], name: "index_taggings_on_tag_id"
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", force: :cascade do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false t.string "encrypted_password", default: "", null: false