This project is archived and is in readonly mode.
Nested resources inherit requirements on parent ids
-
David Jones
+1 this makes a lot of sense. Since the child resource inherits the parent into their URL surely you'd expect the requirements to come across with it.
-
Andrew White
- Assigned user set to Andrew White
- State changed from new to open
- Milestone cleared.
- Importance changed from to Medium
-
Andrew White
This almost works with the new router now:
# Works resources :movies, :id => /\d+/ do resources :reviews end # Works resources :movies, :constraints => { :id => /\d+/ } do resources :reviews end # Works scope :id => /\d+/ do resources :movies do resources :reviews end end # Fails scope :constraints => { :id => /\d+/ } do resources :movies do resources :reviews end end # Fails constraints :id => /\d+/ do resources :movies do resources :reviews end endThis is because :constraints is a separate hash in the scope. The attached patch merges the constraints from the scope into the resource options.
-
Repository
- State changed from open to resolved
(from [e717631a8481935e8ac1eeb2445da341bdd4c868]) Merge :constraints from scope into resource options [#2694 Nested resources inherit requirements on parent ids state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/e717631a8481935e8ac1eeb2445da3... -
Anthony Green
I'm still seeing this bug in Actionpack (3.0.0.rc2) but it has been marked as resolved ?
-
Andrew White
You are using the new router dsl, right? I'm asking because your example is using the old syntax (and it doesn't work using the old syntax). If you're using the old syntax then nothing will have changed as that's been kept the same deliberately to ease the migration of old apps.
-
Anthony Green
Now I'm not sure if this is the same issue or a slight variation:
resources :foo, :constraints => { :id => /\d+/ } do
resources :bar endrake routes:
edit_foo_bar GET /foo/:foo_id/bar/:id/edit(.:format) {:id=>/\d+/, :foo_id=>/\d+/, ...} foo_bar GET /foo/:foo_id/bar/:id(.:format) {:id=>/\d+/, :foo_id=>/\d+/, ...} foo_bar PUT /foo/:foo_id/bar/:id(.:format) {:id=>/\d+/, :foo_id=>/\d+/, ...} foo_bar DELETE /foo/:foo_id/bar/:id(.:format) {:id=>/\d+/, :foo_id=>/\d+/, ...}here you can see both :foo_id and :id inherit the constraint. It should only be :foo_id
-
Anthony Green
Moments later I spot the typo:
the nested resource should be declared singularly so resource not resources
resources :foo, :constraints => { :id => /\d+/ } do
resource :bar endis there a use case for
resources :foo do
resources :bar endor should it throw an error ?
