Commit b944d9c9 by tady

add paper_trail, tag.body

parent 6c33051f
...@@ -119,3 +119,6 @@ gem 'validates_email_format_of' ...@@ -119,3 +119,6 @@ gem 'validates_email_format_of'
# Presentaion layer # Presentaion layer
gem 'draper', '~> 1.3' gem 'draper', '~> 1.3'
# ActiveRecord versioning
gem 'paper_trail', '~> 3.0.0'
...@@ -210,6 +210,9 @@ GEM ...@@ -210,6 +210,9 @@ GEM
oauth2 (~> 0.9.3) oauth2 (~> 0.9.3)
omniauth (~> 1.2) omniauth (~> 1.2)
orm_adapter (0.5.0) orm_adapter (0.5.0)
paper_trail (3.0.0)
activerecord (>= 3.0, < 5.0)
activesupport (>= 3.0, < 5.0)
parser (2.1.5) parser (2.1.5)
ast (~> 1.1) ast (~> 1.1)
slop (~> 3.4, >= 3.4.5) slop (~> 3.4, >= 3.4.5)
...@@ -372,6 +375,7 @@ DEPENDENCIES ...@@ -372,6 +375,7 @@ DEPENDENCIES
mysql2 mysql2
nokogiri nokogiri
omniauth-google-oauth2 omniauth-google-oauth2
paper_trail (~> 3.0.0)
poltergeist poltergeist
premailer premailer
pry-rails pry-rails
......
...@@ -10,11 +10,17 @@ class TagDecorator < Draper::Decorator ...@@ -10,11 +10,17 @@ class TagDecorator < Draper::Decorator
# end # end
# end # end
# tagページのURL
# urlエンコードを施す
def show_path
h.show_tag_path(name: h.url_encode(model.name))
end
# tagをtree viewで表示する # tagをtree viewで表示する
def tree_view_node def tree_view_node
_html = '' _html = ''
_html += %Q{ _html += %Q{
<a href="#{ h.posts_path(q: '#' + model.name) }" data-name="#{model.name}"> <a href="#{ self.show_path }" data-name="#{model.name}">
#{model.name} <span class="badge">#{model.posts.count}</span> #{model.name} <span class="badge">#{model.posts.count}</span>
</a> </a>
} }
......
...@@ -2,8 +2,12 @@ class Tag < ActiveRecord::Base ...@@ -2,8 +2,12 @@ class Tag < ActiveRecord::Base
has_many :post_tags has_many :post_tags
has_many :posts, through: :post_tags has_many :posts, through: :post_tags
# for tree structure
has_ancestry has_ancestry
# for versioning
has_paper_trail
default_scope { order(:updated_at => :desc) } default_scope { order(:updated_at => :desc) }
# 自分のタグに紐づくPostをすべて`other_tag`へ移動する # 自分のタグに紐づくPostをすべて`other_tag`へ移動する
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<%### Post meta ###%> <%### Post meta ###%>
<% @post.tags.each do |tag| %> <% @post.tags.each do |tag| %>
<span class="label label-info"> <span class="label label-info">
<a href="<%= show_tag_path(name: url_encode(tag.name)) %>">#<%= tag.name %></a> <a href="<%= tag.decorate.show_path %>">#<%= tag.name %></a>
</span> </span>
<% end %> <% end %>
<span class="label label-success"> <span class="label label-success">
......
class AddBodyToTag < ActiveRecord::Migration
def change
add_column :tags, :body, :text
end
end
class CreateVersions < ActiveRecord::Migration
def self.up
create_table :versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
t.string :event, :null => false
t.string :whodunnit
t.text :object
t.datetime :created_at
end
add_index :versions, [:item_type, :item_id]
end
def self.down
remove_index :versions, [:item_type, :item_id]
drop_table :versions
end
end
...@@ -11,7 +11,7 @@ ...@@ -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: 20140106160129) do ActiveRecord::Schema.define(version: 20140302053916) do
create_table "comments", force: true do |t| create_table "comments", force: true do |t|
t.integer "author_id" t.integer "author_id"
...@@ -47,6 +47,7 @@ ActiveRecord::Schema.define(version: 20140106160129) do ...@@ -47,6 +47,7 @@ ActiveRecord::Schema.define(version: 20140106160129) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "ancestry" t.string "ancestry"
t.text "body"
end end
add_index "tags", ["ancestry"], name: "index_tags_on_ancestry", using: :btree add_index "tags", ["ancestry"], name: "index_tags_on_ancestry", using: :btree
...@@ -74,4 +75,15 @@ ActiveRecord::Schema.define(version: 20140106160129) do ...@@ -74,4 +75,15 @@ ActiveRecord::Schema.define(version: 20140106160129) do
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "versions", force: true do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment