Skip to content

Commit

Permalink
Merge pull request #45383 from t27duck/scaffold_destroy_use_see_other
Browse files Browse the repository at this point in the history
Scaffold destroy action returns status code 303
  • Loading branch information
jonathanhefner committed Oct 14, 2022
2 parents 5afe9cb + d6715c7 commit 56ee229
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions guides/source/action_controller_overview.md
Expand Up @@ -486,7 +486,7 @@ class LoginsController < ApplicationController
session.delete(:current_user_id)
# Clear the memoized current user
@_current_user = nil
redirect_to root_url
redirect_to root_url, status: :see_other
end
end
```
Expand All @@ -508,7 +508,7 @@ class LoginsController < ApplicationController
def destroy
session.delete(:current_user_id)
flash[:notice] = "You have successfully logged out."
redirect_to root_url
redirect_to root_url, status: :see_other
end
end
```
Expand Down
5 changes: 5 additions & 0 deletions railties/CHANGELOG.md
@@ -1,3 +1,8 @@
* Send 303 See Other status code back for the destroy action on newly generated
scaffold controllers.

*Tony Drake*

* Add `Rails.application.deprecators` as a central point to manage deprecators
for an application.

Expand Down
Expand Up @@ -43,7 +43,7 @@ class <%= controller_class_name %>Controller < ApplicationController
# DELETE <%= route_url %>/1
def destroy
@<%= orm_instance.destroy %>
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
end

private
Expand Down
Expand Up @@ -44,6 +44,7 @@ def test_controller_skeleton_is_created
assert_instance_method :destroy, content do |m|
assert_match(/@user\.destroy/, m)
assert_match(/User was successfully destroyed/, m)
assert_match(/status: :see_other/, m)
end

assert_instance_method :set_user, content do |m|
Expand Down

0 comments on commit 56ee229

Please sign in to comment.