Sha256: 1250009891c11f857a1e6add6f03d6d9813dfb5c45e7c77a9b5ddb5a22dd226c
Contents?: true
Size: 824 Bytes
Versions: 12
Compression:
Stored size: 824 Bytes
Contents
# frozen_string_literal: true module Motor class ActiveStorageAttachmentsController < ApiBaseController wrap_parameters :data, except: %i[include fields] load_and_authorize_resource :attachment, class: 'ActiveStorage::Attachment', parent: false def create if @attachment.record.respond_to?("#{@attachment.name}_attachment=") || @attachment.record.respond_to?("#{@attachment.name}_attachments=") @attachment.record.public_send(@attachment.name).attach( io: StringIO.new(params.dig(:data, :file, :io).to_s.encode('ISO-8859-1')), filename: params.dig(:data, :file, :filename) ) head :ok else head :unprocessable_entity end end private def attachment_params params.require(:data).except(:file).permit! end end end
Version data entries
12 entries across 12 versions & 1 rubygems