jackdempsey / acts_as_commentable

The ActiveRecord acts_as_commentable plugin
http://juixe.com/svn/acts_as_commentable/
MIT License
834 stars 176 forks source link

Comment.find_commentable can query non commentable models #18

Closed CapyTheBeara closed 13 years ago

CapyTheBeara commented 13 years ago

For example, if we had a User class that was not commentable, then this method could do something like

 > Comment.find_commentable('User', 1)
 => #<User id:1, secret_info: 'foo'>

Perhaps the scope of this method should be restricted to just commentable models by checking if it responds to a commentable method? In the pull request, I used

  def find_commentable(commentable_str, commentable_id)
    model = commentable_str.constantize
    model.respond_to?(:find_comments_for) ? model.find(commentable_id) : nil
 end
jackdempsey commented 13 years ago

Thanks monocle, merged and pushed out as v3.0.1.