Files
nairobi/app/models/comment.rb
2015-08-02 13:35:48 +02:00

21 lines
505 B
Ruby

class Comment < ActiveRecord::Base
acts_as_nested_set scope: [:commentable_id, :commentable_type]
acts_as_votable
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