From 507d06845949d8e3ce691598443a0b376bd981a2 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 27 Oct 2024 14:03:13 +0100 Subject: [PATCH 1/2] Configure endpoint to support bulk updates --- app/controllers/application_controller.rb | 11 +++++++++++ app/controllers/guests_controller.rb | 4 ++++ config/environments/development.rb | 2 ++ config/routes.rb | 1 + 4 files changed, 18 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..7d14012 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,13 @@ class ApplicationController < ActionController::Base + after_action :set_csrf_cookie + + private + + def set_csrf_cookie + cookies["csrf-token"] = { + value: form_authenticity_token, + secure: Rails.env.production?, + same_site: :strict, + } + end end diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 925770f..53ef565 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -75,6 +75,10 @@ class GuestsController < ApplicationController redirect_to guests_url end + def bulk_update + render json: {}, status: :ok + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/config/environments/development.rb b/config/environments/development.rb index 794f390..f39246f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -73,4 +73,6 @@ Rails.application.configure do # Raise error when a before_action's only/except options reference missing actions config.action_controller.raise_on_missing_callback_actions = true + + config.hosts << "libre-wedding-planner.app.localhost" end diff --git a/config/routes.rb b/config/routes.rb index 6e4d17b..d1697bc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ Rails.application.routes.draw do resources :groups, only: :index resources :guests do post :import, on: :collection + post :bulk_update, on: :collection end resources :expenses resources :tables_arrangements, only: [:index, :show] From b8dfcf326f237dfbad77886b694f0fd6f3ed0087 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 27 Oct 2024 19:01:12 +0100 Subject: [PATCH 2/2] Implement the actual status update --- app/controllers/guests_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/guests_controller.rb b/app/controllers/guests_controller.rb index 53ef565..76bfda4 100644 --- a/app/controllers/guests_controller.rb +++ b/app/controllers/guests_controller.rb @@ -76,6 +76,7 @@ class GuestsController < ApplicationController end def bulk_update + Guest.where(id: params[:guest_ids]).update!(params.require(:properties).permit(:status)) render json: {}, status: :ok end