Added comments

This commit is contained in:
Godwin
2016-07-09 15:25:27 -07:00
parent 8d010eaf3b
commit c6f8d4ed58
21 changed files with 1206 additions and 27 deletions
+37
View File
@@ -0,0 +1,37 @@
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
+8
View File
@@ -146,6 +146,14 @@ class Workshop < ActiveRecord::Base
end
return notify_list
end
def comments
Comment.for(self)
end
def add_comment(user, comment)
Comment.create_for(self, user, comment)
end
private
def make_slug