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.

38 lines
742 B

9 years ago
class Comment < ActiveRecord::Base
belongs_to :user
9 years ago
def comment_object
model_type.classify.constantize.find(model_id)
end
9 years ago
def set_model(model)
model_type = model.class.name.tableize
model_id = model.id
end
9 years ago
def self.for(model)
where(model_type: model.class.name.tableize, model_id: model.id).order(created_at: :asc)
end
9 years ago
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
9 years ago
def add_comment(user, comment)
Comment.create_for(self, user, comment)
end
def comments
Comment.for(self)
end
def reply?
model_type == 'comments'
9 years ago
end
end