Sha256: 58e393360053d45b08f9f351a049cf66e33df8c1e6985107277fdb0b1cbbf674
Contents?: true
Size: 678 Bytes
Versions: 1
Compression:
Stored size: 678 Bytes
Contents
class ActiveRecord::Base module CommentingExtensions def comment_count commentable? self.comments.size end def comment_with(attributes) commentable?(true) begin comment = Comment.create(attributes) raise Comment::Error, "Comment could not be saved with" if comment.new_record? comment.commentables << self rescue end end private def commentable?(should_raise = false) #:nodoc: unless flag = respond_to?(:<%= parent_association_name -%>s) raise "#{self.class} is not a commentable model" if should_raise end flag end end include CommentingExtensions end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
has_many_polymorphs-2.11 | generators/commenting/templates/commenting_extensions.rb |