Module: Bravo::Comment::Finders

Defined in:
lib/comment/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



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

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) ⇒ Object

Helper class method to lookup all comments assigned to all commentable types for a given user.



19
20
21
# File 'lib/comment/comment_methods.rb', line 19

def find_comments_by_user(user)
  where(["user_id = ?", user.id]).order("created_at DESC")
end

#find_comments_for_commentable(commentable_type, commentable_id) ⇒ Object

Helper class method to look up all comments for commentable class name and commentable id.



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

def find_comments_for_commentable(commentable_type, commentable_id)
  where(["commentable_type = ? and commentable_id = ?", commentable_type, commentable_id]).order("created_at DESC")
end