Class: Avo::AttachmentsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- BaseApplicationController
- ApplicationController
- Avo::AttachmentsController
- Defined in:
- app/controllers/avo/attachments_controller.rb
Constant Summary
Constants included from Concerns::FindAssociationField
Concerns::FindAssociationField::ASSOCIATIONS
Instance Method Summary collapse
Methods inherited from BaseApplicationController
#exception_logger, #turbo_frame_request?
Methods included from Concerns::FindAssociationField
Methods included from Concerns::Breadcrumbs
#add_breadcrumb, #avo_breadcrumbs
Methods included from UrlHelpers
#edit_resource_path, #new_resource_path, #preview_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, #body_classes, #button_classes, #chart_color, #container_classes, #d, #decode_filter_params, #e, #editor_file_path, #editor_url, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #manual_frame_cookie_name, #manual_frame_remembered?, #mount_path, #number_to_social, #possibly_rails_authentication?, #render_header_menu_items, #render_license_warning, #root_path_without_url, #rtl?, #safe_blob_path, #safe_blob_representation_url, #safe_blob_url, #text_direction, #ui, #wrap_in_modal
Methods included from SummaryChartHelper
Methods included from ResourcesHelper
#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_selector_data_attributes, #record_path, #record_title, #resource_for_record, #resource_grid, #resource_show_path, #resource_table
Methods included from CommonController
#default_url_options, #extra_default_url_options
Methods included from InitializesAvo
#_current_user, #context, #init_app, #load_appearance_settings
Methods included from Concerns::SafeCall
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/avo/attachments_controller.rb', line 9 def create association_name = BaseResource.(@record, params[:attachment_key]) if association_name return unless (association_name) blob = ActiveStorage::Blob.create_and_upload! io: params[:file].to_io, filename: params[:filename] @record.send(association_name).attach blob elsif params[:key].present? return unless blob = ActiveStorage::Blob.create_and_upload! io: params[:file].to_io, filename: params[:filename] else raise ActionController::BadRequest.new("Could not find the attachment association for #{params[:attachment_key]} (check the `attachment_key` for this Trix field)") end render json: { url: main_app.url_for(blob), href: main_app.url_for(blob) } end |
#destroy ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/avo/attachments_controller.rb', line 31 def destroy if :delete = ActiveStorage::Attachment.find(params[:attachment_id]) if .present? ActiveRecord::Base.transaction do @destroyed = .destroy! @record.reload unless @record.save @destroyed = nil raise ActiveRecord::Rollback end end if @destroyed.present? flash[:notice] = t("avo.attachment_destroyed") else flash[:error] = @record.errors..join(", ") end else t("avo.failed_to_find_attachment") end else flash[:notice] = t("avo.not_authorized") end respond_to do |format| format.turbo_stream do render "destroy" end end end |