Skip to content

Commit

Permalink
Update default scaffold templates to set 303 (See Other) as status c…
Browse files Browse the repository at this point in the history
…ode on redirect for the update action

XHR requests other than GET or POST have issues when using 302
(e.g browsers trying to follow the redirect using the
original request method resulting in double PATCH/PUT)

This should be reverted when / if
#45393 is merged
  • Loading branch information
guilleiguaran committed Jul 1, 2023
1 parent 8a158ed commit 5ed37b3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,10 @@
* Update default scaffold templates to set 303 (See Other) as status code
on redirect for the update action for XHR requests other than GET or POST
to avoid issues (e.g browsers trying to follow the redirect using the
original request method resulting in double PATCH/PUT)

*Guillermo Iguaran*

* The new `config.autoload_lib_once` is similar to `config.autoload_lib`,
except that it adds `lib` to `config.autoload_once_paths` instead.

Expand Down
Expand Up @@ -34,7 +34,7 @@ class <%= controller_class_name %>Controller < ApplicationController
# PATCH/PUT <%= route_url %>/1
def update
if @<%= orm_instance.update("#{singular_table_name}_params") %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>, status: :see_other
else
render :edit, status: :unprocessable_entity
end
Expand Down
Expand Up @@ -41,6 +41,7 @@ def test_controller_skeleton_is_created

assert_instance_method :update, content do |m|
assert_match(/@user\.update\(user_params\)/, m)
assert_match(/status: :see_other/, m)
end

assert_instance_method :destroy, content do |m|
Expand Down

0 comments on commit 5ed37b3

Please sign in to comment.