Sha256: c7f43664831dca85124efd6fbfeaf79a2271c6cfb40335d94e4fba04bd34757e
Contents?: true
Size: 622 Bytes
Versions: 3
Compression:
Stored size: 622 Bytes
Contents
module Parole module Commentable extend ActiveSupport::Concern included do # Default options for all comments associations association_options = { class_name: 'Comment', as: :commentable, dependent: :destroy } # All comments for the record has_many :comments, association_options # Role-specific comments for the record commentable_options.fetch(:roles).each do |role| options = association_options.merge before_add: lambda { |_, comment| comment.role = role } has_many :"#{role}_comments", lambda { where(role: role) }, options end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
parole-0.1.2 | lib/parole/commentable.rb |
parole-0.1.1 | lib/parole/commentable.rb |
parole-0.1 | lib/parole/commentable.rb |