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
# File 'lib/comment_methods.rb', line 38

def find_commentable(commentable_str, commentable_id)
  commentable_str.constantize.find(commentable_id)
end

#find_comments_by_user(user) ⇒ Object

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



20
21
22
23
24
25
# File 'lib/comment_methods.rb', line 20

def find_comments_by_user(user)
  find(:all,
    :conditions => ["user_id = ?", user.id],
    :order => "created_at DESC"
  )
end

#find_comments_for_commentable(commentable_str, commentable_id) ⇒ Object

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



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

def find_comments_for_commentable(commentable_str, commentable_id)
  find(:all,
    :conditions => ["commentable_type = ? and commentable_id = ?", commentable_str, commentable_id],
    :order => "created_at DESC"
  )
end