Module: ActiveRecord::Acts::MuckComment::SingletonMethods

Defined in:
lib/active_record/acts/muck_comment.rb

Overview

class methods

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



56
57
58
# File 'lib/active_record/acts/muck_comment.rb', line 56

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.



38
39
40
41
42
43
# File 'lib/active_record/acts/muck_comment.rb', line 38

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.



47
48
49
50
51
52
# File 'lib/active_record/acts/muck_comment.rb', line 47

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