Sha256: 5687f0a8f2aa9ca9ab3b0377b77c37d78c0d10bbaf59c64acddbb70e0a43ae4b

Contents?: true

Size: 1.09 KB

Versions: 31

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    module AttachmentMethods
      private

      def build_attachment(attached_to = nil)
        attached_to = @attached_to if attached_to.blank?
        attached_to = form.current_organization if attached_to.blank? && form.respond_to?(:current_organization)

        @attachment = Attachment.new(
          title: { I18n.locale => @form.attachment.title },
          attached_to: attached_to,
          file: @form.attachment.file, # Define attached_to before this
          content_type: @form.attachment.file.content_type
        )
      end

      def attachment_invalid?
        if attachment.invalid? && attachment.errors.has_key?(:file)
          @form.attachment.errors.add :file, attachment.errors[:file]
          true
        end
      end

      def create_attachment
        attachment.attached_to = @attached_to
        attachment.save!
      end

      def process_attachments?
        @form.attachment && @form.attachment.file.present? &&
          !@form.attachment.file.is_a?(Decidim::ApplicationUploader)
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.9 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.8 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.7 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.6 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.10 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.9 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.5 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.8 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.4 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.3 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.7 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.5 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.2 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.1 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.4 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.0 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.3 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.0.rc2 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.27.0.rc1 app/commands/decidim/initiatives/attachment_methods.rb
decidim-initiatives-0.26.2 app/commands/decidim/initiatives/attachment_methods.rb