Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

4.1.0.rc1: Custom route patterns are leaked to sub resources #14306

Closed
byroot opened this Issue · 6 comments

4 participants

@byroot

The following routes

Shipit::Application.routes.draw do
  resources :foos, :id => /\w+/, :only => :show do
    resources :bars, only: :show
  end
end

generate:

 Prefix Verb URI Pattern                      Controller#Action
foo_bar GET  /foos/:foo_id/bars/:id(.:format) bars#show {:id=>/\w+/, :foo_id=>/\w+/}
    foo GET  /foos/:id(.:format)              foos#show {:id=>/\w+/}

I would expect:

 Prefix Verb URI Pattern                      Controller#Action
foo_bar GET  /foos/:foo_id/bars/:id(.:format) bars#show {:foo_id=>/\w+/}
    foo GET  /foos/:id(.:format)              foos#show {:id=>/\w+/}

It can be easily worked around by explicitly defined subresource id as /\d+/.
This bug is present as of 58db2df (current 4-1-stable HEAD)

/cc @arthurnn @davidcornu

@robin850 robin850 added this to the 4.0.4 milestone
@pixeltrix
Owner

@byroot is this a regression?

@davidcornu

@pixeltrix This is also the case in 4.0.3.

@davidcornu

And in 3.2.17.

@byroot

Damn, I though it was a regression, my bad.

Then maybe it's the intended behaviour, but I'm very surprised.

@davidcornu

Yeah, sub-resources having the same id pattern as their parents seems like a false assumption to me.

@pixeltrix
Owner

This is the expected behaviour and is tested for here.

The thing to remember is that resources is essentially a macro command for generating standard routes - there's no 'magic' happening. Therefore when you specify a constraint on a resource it gets added to the scope's list of constraints and is passed to nested scopes.

@pixeltrix pixeltrix closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.