Class: Spina::Admin::AttachmentsController
- Inherits:
-
AdminController
- Object
- ActionController::Base
- AdminController
- Spina::Admin::AttachmentsController
- Defined in:
- app/controllers/spina/admin/attachments_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #inline_upload ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from AdminController
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 18 def create @attachments = params[:attachment][:files].map do |file| next if file.blank? # Skip the blank string posted by the hidden files[] field = Attachment.create() .file.attach(file) end.compact respond_to do |format| format.turbo_stream { render turbo_stream: turbo_stream.prepend("attachments", partial: "attachment", collection: @attachments) } format.html { redirect_to spina. } end end |
#destroy ⇒ Object
57 58 59 60 61 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 57 def destroy @attachment = Attachment.find(params[:id]) @attachment.destroy render turbo_stream: turbo_stream.remove(@attachment) end |
#edit ⇒ Object
14 15 16 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 14 def edit @attachment = Attachment.find(params[:id]) end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 6 def index @attachments = Attachment.sorted.with_attached_file.with_filename(params[:query].to_s).page(params[:page]).per(25) end |
#inline_upload ⇒ Object
33 34 35 36 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 33 def inline_upload @attachment = Attachment.create() render turbo_stream: turbo_stream.append(params[:select_id], partial: "parts/attachments/attachment", object: @attachment) end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 10 def show @attachment = Attachment.find(params[:id]) end |
#update ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 38 def update @attachment = Attachment.find(params[:id]) old_signed_id = @attachment.file&.blob&.signed_id @attachment.update() if params[:attachment].present? if params[:filename].present? extension = @attachment.file.filename.extension filename = "#{params[:filename]}.#{extension}" @attachment.file.blob.update(filename: filename) end # Replace all occurrences of the old signed blob ID # with the new ID in a background job if @attachment.reload.file&.blob&.signed_id != old_signed_id Spina::ReplaceSignedIdJob.perform_later(old_signed_id, @attachment.file&.blob&.signed_id) end render @attachment end |