Bike!Bike! Website!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
742 B

class Comment < ActiveRecord::Base
belongs_to :user
def comment_object
model_type.classify.constantize.find(model_id)
end
def set_model(model)
model_type = model.class.name.tableize
model_id = model.id
end
def self.for(model)
where(model_type: model.class.name.tableize, model_id: model.id).order(created_at: :asc)
end
def self.create_for(model, user, comment)
create(
model_type: model.class.name.tableize,
model_id: model.id,
user_id: user.id,
comment: comment
)
end
def add_comment(user, comment)
Comment.create_for(self, user, comment)
end
def comments
Comment.for(self)
end
def reply?
model_type == 'comments'
end
end