Skip to content

Commit 56ee229

Browse files
Merge pull request rails#45383 from t27duck/scaffold_destroy_use_see_other
Scaffold destroy action returns status code 303
2 parents 5afe9cb + d6715c7 commit 56ee229

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

guides/source/action_controller_overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class LoginsController < ApplicationController
486486
session.delete(:current_user_id)
487487
# Clear the memoized current user
488488
@_current_user = nil
489-
redirect_to root_url
489+
redirect_to root_url, status: :see_other
490490
end
491491
end
492492
```
@@ -508,7 +508,7 @@ class LoginsController < ApplicationController
508508
def destroy
509509
session.delete(:current_user_id)
510510
flash[:notice] = "You have successfully logged out."
511-
redirect_to root_url
511+
redirect_to root_url, status: :see_other
512512
end
513513
end
514514
```

railties/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
* Send 303 See Other status code back for the destroy action on newly generated
2+
scaffold controllers.
3+
4+
*Tony Drake*
5+
16
* Add `Rails.application.deprecators` as a central point to manage deprecators
27
for an application.
38

railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class <%= controller_class_name %>Controller < ApplicationController
4343
# DELETE <%= route_url %>/1
4444
def destroy
4545
@<%= orm_instance.destroy %>
46-
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
46+
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
4747
end
4848

4949
private

railties/test/generators/scaffold_controller_generator_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def test_controller_skeleton_is_created
4444
assert_instance_method :destroy, content do |m|
4545
assert_match(/@user\.destroy/, m)
4646
assert_match(/User was successfully destroyed/, m)
47+
assert_match(/status: :see_other/, m)
4748
end
4849

4950
assert_instance_method :set_user, content do |m|

0 commit comments

Comments
 (0)