From 2013237150010afd00404840ad7235ce76826089 Mon Sep 17 00:00:00 2001 From: Lois Wells Date: Wed, 22 Jan 2025 17:37:30 +0000 Subject: [PATCH] add route to allow images to be updated --- app/controllers/api/projects/images_controller.rb | 12 ++++++++++++ config/routes.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/projects/images_controller.rb b/app/controllers/api/projects/images_controller.rb index bb55f4ec..7833ea24 100644 --- a/app/controllers/api/projects/images_controller.rb +++ b/app/controllers/api/projects/images_controller.rb @@ -17,6 +17,18 @@ def create @project.images.attach(params[:images]) render '/api/projects/images', formats: [:json] end + + def update + @project = Project.find_by!(identifier: params[:project_id]) + authorize! :update, @project + + puts params[:image] + puts 'the filename is ' + params[:image].original_filename + existing_image = @project.images.find { |i| i.blob.filename == params[:image].original_filename } + existing_image.purge + @project.images.attach(params[:image]) + render '/api/projects/images', formats: [:json] + end end end end diff --git a/config/routes.rb b/config/routes.rb index ddf306f2..3f14e74e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -36,7 +36,7 @@ put :toggle_finished, on: :member, to: 'projects#toggle_finished' resource :remix, only: %i[show create], controller: 'projects/remixes' resources :remixes, only: %i[index], controller: 'projects/remixes' - resource :images, only: %i[show create], controller: 'projects/images' + resource :images, only: %i[show create update], controller: 'projects/images' end resource :project_errors, only: %i[create]