Class: Avo::AttachmentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/avo/attachments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#_current_user, #check_avo_license, #context, #exception_logger, #init_app, #render, #turbo_frame_request?

Methods included from UrlHelpers

#edit_resource_path, #new_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resources_path

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #empty_state, #get_model_class, #input_classes, #render_license_warning, #render_license_warnings, #root_path_without_url, #svg

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/avo/attachments_controller.rb', line 9

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

#destroyObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/avo/attachments_controller.rb', line 20

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