Module: ActsAsCommentable::Comment::Finders
- Defined in:
- lib/comment_methods.rb
Instance Method Summary collapse
-
#find_commentable(commentable_str, commentable_id) ⇒ Object
Helper class method to look up a commentable object given the commentable class name and id.
-
#find_comments_by_user(user, role = "comments") ⇒ Object
Helper class method to lookup all comments assigned to all commentable types for a given user.
-
#find_comments_for_commentable(commentable_str, commentable_id, role = "comments") ⇒ Object
Helper class method to look up all comments for commentable class name and commentable id.
Instance Method Details
#find_commentable(commentable_str, commentable_id) ⇒ Object
Helper class method to look up a commentable object given the commentable class name and id
35 36 37 38 |
# File 'lib/comment_methods.rb', line 35 def find_commentable(commentable_str, commentable_id) model = commentable_str.constantize model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil end |
#find_comments_by_user(user, role = "comments") ⇒ Object
Helper class method to lookup all comments assigned to all commentable types for a given user.
23 24 25 |
# File 'lib/comment_methods.rb', line 23 def find_comments_by_user(user, role = "comments") where(["user_id = ? and role = ?", user.id, role]).order("created_at DESC") end |
#find_comments_for_commentable(commentable_str, commentable_id, role = "comments") ⇒ Object
Helper class method to look up all comments for commentable class name and commentable id.
29 30 31 |
# File 'lib/comment_methods.rb', line 29 def find_comments_for_commentable(commentable_str, commentable_id, role = "comments") where(["commentable_type = ? and commentable_id = ? and role = ?", commentable_str, commentable_id, role]).order("created_at DESC") end |