Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8251 (closed enhancement: duplicate)

Opened 3 years ago

Last modified 3 years ago

replace outerresource_action_innerresource_path with action_outerresource_innerresource_path

Reported by: dchelimsky Assigned to: core
Priority: normal Milestone: 1.x
Component: ActionPack Version: edge
Severity: normal Keywords: name_prefix, new_, edit_
Cc:

Description

When name_prefixing nesting resources, I think that a named route that includes an action should start with that action. For example, given Groups with nested Users

new_group_user_path(@group)

would be more intuitive than

group_new_user_path(@group)

The same should be true for any action (i.e. edit, update, etc). It appears that this is the case for "formatted" already, where the named route for the above is:

formatted_group_user_path(@group)

I will create a patch for this if there is interest.

Cheers, David

Attachments

improve_named_routes_with_nested_resources_and_actions.patch (12.8 kB) - added by dchelimsky on 06/01/07 02:45:51.
improve_named_routes_with_nested_resources_and_actions-2.patch (18.2 kB) - added by dchelimsky on 06/03/07 14:36:36.

Change History

05/29/07 20:40:00 changed by josh

  • status changed from new to closed.
  • resolution set to wontfix.

Closing because there is no proposed patch.

05/31/07 11:16:44 changed by dchelimsky

  • status changed from closed to reopened.
  • resolution deleted.

OK - here comes a patch.

This patch covers the following:

new_outer_inner_path => outers/1/inners/new
formatted_new_outer_inner_path => outers/1/inners/new.xml
edit_outer_inner_path => outers/1/inners/new
formatted_edit_outer_inner_path => outers/1/inners/new.xml

It does not cover named actions. For example:

preview_new_outer_inner_path => outers/1/inners/new/preview

The tests for those paths are a bit more difficult for me to understand, so I'll submit those in a separate patch later.

Also, I didn't want to replace the existing names, but rather add these new alternatives, thinking that the existing names would be deprecated first, rather than removed. This caused ResourcesTest#test_restful_routes_dont_generate_duplicates to fail. I commented that test out with an explanation of why it's commented out. Assuming that you accept the patch otherwise, this should probably get deleted.

06/01/07 02:45:51 changed by dchelimsky

  • attachment improve_named_routes_with_nested_resources_and_actions.patch added.

06/01/07 03:11:35 changed by dchelimsky

I updated the patch - this takes care of some more permutations. Still working ...

06/03/07 14:36:36 changed by dchelimsky

  • attachment improve_named_routes_with_nested_resources_and_actions-2.patch added.

06/03/07 14:40:21 changed by dchelimsky

OK - I've added a new patch. This one covers all of the various combinations that used name_prefix including collection actions and formatted responses.

Note that some of the existing generation of named routes was not being tested before (i.e. commenting out lines in resources.rb caused no failures). I added tests for the existing named routes before adding tests for the new named routes.

Cheers, David

06/03/07 19:37:31 changed by dchelimsky

  • status changed from reopened to closed.
  • resolution set to duplicate.

I'm going to re-submit this as a new ticket w/ PATCH in the title.

06/03/07 20:14:52 changed by manfred

You can also just change the title of the ticket, you don't have to re-submit.

06/03/07 20:33:42 changed by dchelimsky

I'll do that in the future. Thanks. Already re-submitted this one as #8558