Sha256: 2ac8233804206769be1b89689a9fcc76eefc0c799642dc65a6396b157a4882ac

Contents?: true

Size: 947 Bytes

Versions: 17

Compression:

Stored size: 947 Bytes

Contents

module Symphonia
  module Attachable

    extend ActiveSupport::Concern

    included do
      has_many :images, -> { order(:position) }, as: :attachable, dependent: :destroy, validate: false, class_name: 'Symphonia::Image'
      has_many :common_files, -> { order(:position) }, as: :attachable, dependent: :destroy, class_name: 'Symphonia::CommonFile'

      # validate do |container|
      #   container.images.each do |img|
      #     next if img.valid?
      #     img.errors.full_messages.each do |msg|
      #       errors.add(:base, "#{img.name}: #{msg}")
      #     end
      #   end
      # end

      def image_attachments=(form_images=[])
        form_images.each do |attribute|
          self.images.build(attachment: attribute)
        end
      end

      def file_attachments=(form_files=[])
        form_files.each do |attribute|
          self.common_files.build(attachment: attribute)
        end
      end

    end

  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
symphonia-3.2.4 lib/symphonia/attachable.rb
symphonia-3.2.3 lib/symphonia/attachable.rb
symphonia-3.2.2 lib/symphonia/attachable.rb
symphonia-3.2.1 lib/symphonia/attachable.rb
symphonia-3.1.5 lib/symphonia/attachable.rb
symphonia-3.1.4 lib/symphonia/attachable.rb
symphonia-3.1.3 lib/symphonia/attachable.rb
symphonia-3.1.2 lib/symphonia/attachable.rb
symphonia-3.1.1 lib/symphonia/attachable.rb
symphonia-3.1.0 lib/symphonia/attachable.rb
symphonia-3.0.3 lib/symphonia/attachable.rb
symphonia-3.0.2 lib/symphonia/attachable.rb
symphonia-2.2.1 lib/symphonia/attachable.rb
symphonia-3.0.1 lib/symphonia/attachable.rb
symphonia-3.0.0 lib/symphonia/attachable.rb
symphonia-2.1.8 lib/symphonia/attachable.rb
symphonia-2.1.7 lib/symphonia/attachable.rb