Sha256: 6f3c670f316d8726960acd003e0f2141fdb64b9724aeee7fa0d01757ddde75ca

Contents?: true

Size: 1002 Bytes

Versions: 90

Compression:

Stored size: 1002 Bytes

Contents

require_dependency "avo/application_controller"

module Avo
  class AttachmentsController < ApplicationController
    before_action :set_resource_name, only: [:destroy, :create]
    before_action :set_resource, only: [:destroy, :create]
    before_action :set_model, only: [:destroy, :create]

    def create
      blob = ActiveStorage::Blob.create_and_upload! io: params[:file], filename: params[:filename]

      @model.send(params[:attachment_key]).attach blob

      render json: {
        url: main_app.url_for(blob),
        href: main_app.url_for(blob)
      }
    end

    def destroy
      attachment = ActiveStorage::Attachment.find(params[:attachment_id])
      path = resource_path(model: @model, resource: @resource)

      if attachment.present?
        attachment.destroy

        redirect_to params[:referrer] || path, notice: t("avo.attachment_destroyed")
      else
        redirect_back fallback_location: path, notice: t("avo.failed_to_find_attachment")
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
avo-2.16.1.pre.1.nativefields app/controllers/avo/attachments_controller.rb
avo-2.16.0 app/controllers/avo/attachments_controller.rb
avo-2.15.3 app/controllers/avo/attachments_controller.rb
avo-2.15.3.pre.1.data.attrs.to.sidebar.items app/controllers/avo/attachments_controller.rb
avo-2.15.2 app/controllers/avo/attachments_controller.rb
avo-2.15.2.pre.1 app/controllers/avo/attachments_controller.rb
avo-2.15.1 app/controllers/avo/attachments_controller.rb
avo-2.15.0 app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.7.polytranslations1 app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.6.nosprockets app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.5.nosprockets app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.4.tosqlfix app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.3.jsbundling app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.2.tailwindcss app/controllers/avo/attachments_controller.rb
avo-2.14.3.pre.1.branding app/controllers/avo/attachments_controller.rb
avo-2.14.2 app/controllers/avo/attachments_controller.rb
avo-2.14.2.pre.1 app/controllers/avo/attachments_controller.rb
avo-2.14.1 app/controllers/avo/attachments_controller.rb
avo-2.14.1.pre.1 app/controllers/avo/attachments_controller.rb
avo-2.14.0 app/controllers/avo/attachments_controller.rb