Permalink
Browse files

added acts_as_taggable to Article.

added bootstrap-tagsinput for acts_as_taggable.
  • Loading branch information...
yoosee committed Feb 18, 2016
1 parent d8dd112 commit 55537571ca50544f1437ada4a64ece6378988042
View
@@ -38,6 +38,8 @@ gem 'will_paginate'
gem 'paperclip', "~> 4.3"
gem 'acts-as-taggable-on', '~> 3.4'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
View
@@ -36,6 +36,8 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
acts-as-taggable-on (3.5.0)
activerecord (>= 3.2, < 5)
addressable (2.4.0)
arel (6.0.3)
autoprefixer-rails (6.3.2)
@@ -208,6 +210,7 @@ PLATFORMS
ruby
DEPENDENCIES
acts-as-taggable-on (~> 3.4)
bcrypt
bootstrap-sass
capybara
@@ -15,6 +15,7 @@
//= require jquery-ui
//= require bootstrap
//= require dropzone.min
//= require bootstrap-tagsinput.min
//= require turbolinks
//= require media
//= require_tree .
@@ -14,4 +14,5 @@
*= require_self
*= require jquery-ui
*= require dropzone.min
*= require bootstrap-tagsinput
*/
@@ -76,7 +76,7 @@ def individual_url article
end
def article_params
params.require(:article).permit(:title, :content, :alt_url, :status)
params.require(:article).permit(:title, :content, :alt_url, :status, :tag_list)
end
end
View
@@ -13,6 +13,8 @@ class Article < ActiveRecord::Base
validates :content, presence: true
validates :alt_url, uniqueness: { case_sensitive: false }, length: { maximum: 500 }, allow_blank: true
acts_as_taggable_on :tags
attr_accessor :url
def previous
@@ -13,6 +13,7 @@
<span class="content"><%== @article.content %></span>
<span class "tags"> <%= render 'articles/tag_list', tag_list: @article.tag_list %></span>
<div><%= link_to "Link to the article", @article.url %></div>
</div>
@@ -4,6 +4,7 @@
<%= f.label :alt_url %> <%= f.text_field :alt_url %>
<%= f.label :content %> <%= f.text_area :content, :size=>'x20' %>
<%= f.label :status %> <%= f.select :status, Article.statuses.keys.to_a %>
<%= f.label :tag_list, "Tags" %> <%= text_field_tag 'article[tag_list]', @article.tag_list.join(','), "data-role" => "tagsinput" %>
<%= f.submit "Submit", class: "btn btn-large btn-primary" %>
<% end %>
@@ -0,0 +1,3 @@
<% tag_list.each do |tag| %>
<span class="label label-primary"><%= tag %></span>
<% end %>
@@ -0,0 +1,31 @@
# 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
# You should make sure that the column created is
# long enough to store the required class names.
t.references :taggable, polymorphic: true
t.references :tagger, polymorphic: true
# Limit is created to prevent MySQL error on index
# length for MyISAM table type: http://bit.ly/vgW2Ql
t.string :context, limit: 128
t.datetime :created_at
end
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
@@ -0,0 +1,20 @@
# This migration comes from acts_as_taggable_on_engine (originally 2)
class AddMissingUniqueIndices < ActiveRecord::Migration
def self.up
add_index :tags, :name, unique: true
remove_index :taggings, :tag_id
remove_index :taggings, [:taggable_id, :taggable_type, :context]
add_index :taggings,
[:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type],
unique: true, name: 'taggings_idx'
end
def self.down
remove_index :tags, :name
remove_index :taggings, name: 'taggings_idx'
add_index :taggings, :tag_id
add_index :taggings, [:taggable_id, :taggable_type, :context]
end
end
@@ -0,0 +1,15 @@
# 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
ActsAsTaggableOn::Tag.reset_column_information
ActsAsTaggableOn::Tag.find_each do |tag|
ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings)
end
end
def self.down
remove_column :tags, :taggings_count
end
end
@@ -0,0 +1,10 @@
# This migration comes from acts_as_taggable_on_engine (originally 4)
class AddMissingTaggableIndex < ActiveRecord::Migration
def self.up
add_index :taggings, [:taggable_id, :taggable_type, :context]
end
def self.down
remove_index :taggings, [:taggable_id, :taggable_type, :context]
end
end
@@ -0,0 +1,10 @@
# This migration comes from acts_as_taggable_on_engine (originally 5)
# This migration is added to circumvent issue #623 and have special characters
# work properly
class ChangeCollationForTagNames < ActiveRecord::Migration
def up
if ActsAsTaggableOn::Utils.using_mysql?
execute("ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;")
end
end
end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160209235300) do
ActiveRecord::Schema.define(version: 20160217220243) do
# Could not dump table "articles" because of following NoMethodError
# undefined method `[]' for nil:NilClass
@@ -36,6 +36,26 @@
t.integer "article_id"
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", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
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|
t.string "name"
t.string "email"

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 5553757

Please sign in to comment.