configures act_as_commentable_with_threading gem [#7]
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -25,7 +25,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
|
|||||||
gem 'devise'
|
gem 'devise'
|
||||||
# Use ActiveModel has_secure_password
|
# Use ActiveModel has_secure_password
|
||||||
# gem 'bcrypt', '~> 3.1.7'
|
# gem 'bcrypt', '~> 3.1.7'
|
||||||
|
gem 'acts_as_commentable_with_threading'
|
||||||
# Use Unicorn as the app server
|
# Use Unicorn as the app server
|
||||||
# gem 'unicorn'
|
# gem 'unicorn'
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,13 @@ 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_commentable_with_threading (2.0.0)
|
||||||
|
activerecord (>= 4.0)
|
||||||
|
activesupport (>= 4.0)
|
||||||
|
awesome_nested_set (>= 3.0)
|
||||||
arel (6.0.2)
|
arel (6.0.2)
|
||||||
|
awesome_nested_set (3.0.2)
|
||||||
|
activerecord (>= 4.0.0, < 5)
|
||||||
bcrypt (3.1.10)
|
bcrypt (3.1.10)
|
||||||
binding_of_caller (0.7.2)
|
binding_of_caller (0.7.2)
|
||||||
debug_inspector (>= 0.0.1)
|
debug_inspector (>= 0.0.1)
|
||||||
@@ -188,6 +194,7 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
acts_as_commentable_with_threading
|
||||||
byebug
|
byebug
|
||||||
capybara
|
capybara
|
||||||
coffee-rails (~> 4.1.0)
|
coffee-rails (~> 4.1.0)
|
||||||
|
|||||||
19
app/models/comment.rb
Normal file
19
app/models/comment.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class Comment < ActiveRecord::Base
|
||||||
|
acts_as_nested_set :scope => [:commentable_id, :commentable_type]
|
||||||
|
|
||||||
|
validates :body, :presence => true
|
||||||
|
validates :user, :presence => true
|
||||||
|
|
||||||
|
belongs_to :commentable, :polymorphic => true
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
def self.build(commentable, user, body)
|
||||||
|
new commentable: commentable,
|
||||||
|
user_id: user.id,
|
||||||
|
body: body
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_parent(params)
|
||||||
|
params[:commentable_type].constantize.find(params[:commentable_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
class Debate < ActiveRecord::Base
|
class Debate < ActiveRecord::Base
|
||||||
|
acts_as_commentable
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :description, presence: true
|
validates :description, presence: true
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
class ActsAsCommentableWithThreadingMigration < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
create_table :comments, :force => true do |t|
|
||||||
|
t.integer :commentable_id
|
||||||
|
t.string :commentable_type
|
||||||
|
t.string :title
|
||||||
|
t.text :body
|
||||||
|
t.string :subject
|
||||||
|
t.integer :user_id, :null => false
|
||||||
|
t.integer :parent_id, :lft, :rgt
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :comments, :user_id
|
||||||
|
add_index :comments, [:commentable_id, :commentable_type]
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
drop_table :comments
|
||||||
|
end
|
||||||
|
end
|
||||||
19
db/schema.rb
19
db/schema.rb
@@ -11,7 +11,24 @@
|
|||||||
#
|
#
|
||||||
# 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: 20150716174358) do
|
ActiveRecord::Schema.define(version: 20150718091702) do
|
||||||
|
|
||||||
|
create_table "comments", force: :cascade do |t|
|
||||||
|
t.integer "commentable_id"
|
||||||
|
t.string "commentable_type"
|
||||||
|
t.string "title"
|
||||||
|
t.text "body"
|
||||||
|
t.string "subject"
|
||||||
|
t.integer "user_id", null: false
|
||||||
|
t.integer "parent_id"
|
||||||
|
t.integer "lft"
|
||||||
|
t.integer "rgt"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "comments", ["commentable_id", "commentable_type"], name: "index_comments_on_commentable_id_and_commentable_type"
|
||||||
|
add_index "comments", ["user_id"], name: "index_comments_on_user_id"
|
||||||
|
|
||||||
create_table "debates", force: :cascade do |t|
|
create_table "debates", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
|
|||||||
Reference in New Issue
Block a user