Files
nairobi/app/models/comment.rb

20 lines
499 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