Class: Avo::AttachmentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Avo::AttachmentsController
- 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 Concerns::Breadcrumbs
#add_breadcrumb, #avo_breadcrumbs
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #related_resources_path, #resource_attach_path, #resource_detach_path, #resource_path, #resource_view_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, #white_panel_classes
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/avo/attachments_controller.rb', line 9 def create blob = ActiveStorage::Blob.create_and_upload! io: params[:file], filename: params[:filename] association_name = BaseResource.(@model, params[:attachment_key]) @model.send(association_name).attach blob render json: { url: main_app.url_for(blob), href: main_app.url_for(blob) } end |
#destroy ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/avo/attachments_controller.rb', line 21 def destroy = ActiveStorage::Attachment.find(params[:attachment_id]) path = resource_path(model: @model, resource: @resource) if .present? .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 |