Sha256: 70a07d9e7137081c49553210952d4d1ba3c92d712bfefe32bc8a025135ba5244
Contents?: true
Size: 1.06 KB
Versions: 69
Compression:
Stored size: 1.06 KB
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 show end def destroy blob = ActiveStorage::Blob.find(params[:signed_attachment_id]) attachment = blob.attachments.find_by record_id: params[:id], record_type: @model.class.to_s if attachment.present? attachment.destroy redirect_to params[:referrer] || resource_path(@model), notice: t("avo.attachment_destroyed") else redirect_back fallback_location: resource_path(@model), notice: t("avo.failed_to_find_attachment") end end end end
Version data entries
69 entries across 69 versions & 1 rubygems