Files
grecia/app/models/comment.rb
2015-07-18 21:49:36 +02:00

20 lines
487 B
Ruby

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