Skip to content

Commit df4386a

Browse files
authored
Merge pull request rails#52764 from jeromedalbert/path-in-controller-generators
Change controller generator to use _path instead of _url for redirects
2 parents 8bac99a + 42ea82a commit df4386a

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

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.") %>, status: :see_other
46+
redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other
4747
end
4848

4949
private

railties/test/generators/scaffold_controller_generator_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,19 @@ def test_controller_skeleton_is_created
3737
assert_instance_method :create, content do |m|
3838
assert_match(/@user = User\.new\(user_params\)/, m)
3939
assert_match(/@user\.save/, m)
40+
assert_match(/redirect_to @user/, m)
4041
end
4142

4243
assert_instance_method :update, content do |m|
4344
assert_match(/@user\.update\(user_params\)/, m)
45+
assert_match(/redirect_to @user/, m)
4446
assert_match(/status: :see_other/, m)
4547
end
4648

4749
assert_instance_method :destroy, content do |m|
4850
assert_match(/@user\.destroy/, m)
4951
assert_match(/User was successfully destroyed/, m)
52+
assert_match(/redirect_to users_path/, m)
5053
assert_match(/status: :see_other/, m)
5154
end
5255

0 commit comments

Comments
 (0)