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 = 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: ) } 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.find(params[:id]) .destroy render turbo_stream: turbo_stream.remove() end |
#edit ⇒ Object
14 15 16 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 14 def edit = Attachment.find(params[:id]) end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 6 def index = 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.create() render turbo_stream: turbo_stream.append(params[:select_id], partial: "parts/attachments/attachment", object: ) end |
#show ⇒ Object
10 11 12 |
# File 'app/controllers/spina/admin/attachments_controller.rb', line 10 def show = 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.find(params[:id]) old_signed_id = .file&.blob&.signed_id .update() if params[:attachment].present? if params[:filename].present? extension = .file.filename.extension filename = "#{params[:filename]}.#{extension}" .file.blob.update(filename: filename) end # Replace all occurrences of the old signed blob ID # with the new ID in a background job if .reload.file&.blob&.signed_id != old_signed_id Spina::ReplaceSignedIdJob.perform_later(old_signed_id, .file&.blob&.signed_id) end render end |