Module: ActsAsCommentable::Comment::Finders

Defined in:
lib/comment_methods.rb

Instance Method Summary collapse

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



38
39
40
41
# File 'lib/comment_methods.rb', line 38

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.



25
26
27
# File 'lib/comment_methods.rb', line 25

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.



31
32
33
34
# File 'lib/comment_methods.rb', line 31

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