class Avo::AttachmentsController

def 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

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