diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index cf21fcade7c0f..f3070cf385c72 100644 --- a/railties/CHANGELOG.md +++ b/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. diff --git a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt index 3a337bf213ab1..bef88fd20ab34 100644 --- a/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt +++ b/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt @@ -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 diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index ad8cff47a7cdf..aafa6c06763fd 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -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|