Skip to content

Commit e39870a

Browse files
authored
Fix bug multiple request when drag and drop position stage (#589)
1 parent e867abd commit e39870a

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

app/controllers/accounts/pipelines_controller.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,13 @@ def create
177177

178178
# PATCH/PUT /pipelines/1 or /pipelines/1.json
179179
def update
180-
respond_to do |format|
181-
if @pipeline.update(pipeline_params)
180+
if @pipeline.update(pipeline_params)
181+
respond_to do |format|
182182
format.html do
183183
redirect_to account_pipeline_path(Current.account, @pipeline),
184184
notice: t('flash_messages.updated', model: Pipeline.model_name.human)
185185
end
186-
format.json { render :show, status: :ok, location: @pipeline }
187-
else
188-
format.html { render :edit, status: :unprocessable_entity }
189-
format.json { render json: @pipeline.errors, status: :unprocessable_entity }
186+
format.turbo_stream
190187
end
191188
end
192189
end

app/javascript/controllers/drag_stages_position_controller.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export default class extends Controller {
3232
url: this.data.get('url'),
3333
type: 'PATCH',
3434
data: data,
35+
beforeSend: (xhr) => {
36+
xhr.setRequestHeader("Accept", "text/vnd.turbo-stream.html");
37+
return true;
38+
},
39+
success: (response) => {
40+
Turbo.renderStreamMessage(response);
41+
},
42+
error: (response) => {
43+
Turbo.renderStreamMessage(response);
44+
},
3545
});
3646
}
3747
}

app/views/accounts/pipelines/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= form_with(model: pipeline, url: pipeline.persisted? ? account_pipeline_path(Current.account, pipeline) : account_pipelines_path(Current.account), class: "flex flex-col gap-5") do |form| %>
1+
<%= form_with(model: pipeline, url: pipeline.persisted? ? account_pipeline_path(Current.account, pipeline) : account_pipelines_path(Current.account), class: "flex flex-col gap-5", data: { turbo: false }) do |form| %>
22
<% if pipeline.errors.any? %>
33
<div>
44
<ul>

0 commit comments

Comments
 (0)