Skip to content

Commit 552b313

Browse files
Revert "Disabled Turbo for the new and create action as it caused issues with CSRF verification for the new form"
This reverts commit 37461d2.
1 parent 7a43324 commit 552b313

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

app/controllers/distributions_controller.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class DistributionsController < ApplicationController
77
include DateRangeHelper
88
include DistributionHelper
99

10-
before_action :enable_turbo!, only: %i[show]
10+
before_action :enable_turbo!, only: %i[new show]
1111
skip_before_action :authenticate_user!, only: %i(calendar)
1212
skip_before_action :authorize_user, only: %i(calendar)
1313

@@ -101,7 +101,11 @@ def create
101101
perform_inventory_check
102102
schedule_reminder_email(result.distribution) if @distribution.reminder_email_enabled
103103

104-
redirect_to distribution_path(result.distribution), notice: "Distribution created!"
104+
respond_to do |format|
105+
format.turbo_stream do
106+
redirect_to distribution_path(result.distribution), notice: "Distribution created!"
107+
end
108+
end
105109
else
106110
@distribution = result.distribution
107111
if request_id
@@ -128,8 +132,16 @@ def create
128132
end
129133

130134
flash_error = insufficient_error_message(result.error.message)
131-
flash.now[:error] = flash_error
132-
render :new
135+
136+
respond_to do |format|
137+
format.turbo_stream do
138+
flash.now[:error] = flash_error
139+
render turbo_stream: [
140+
turbo_stream.replace(@distribution, partial: "form", locals: {distribution: @distribution, date_place_holder: @distribution.issued_at}),
141+
turbo_stream.replace("flash", partial: "shared/flash")
142+
], status: :bad_request
143+
end
144+
end
133145
end
134146
end
135147

0 commit comments

Comments
 (0)