Rails 3 Nested resource routes inherit parental restrictions; how can I avoid them?

It defines the restriction on "id" in the parent resource:

resources :foo, constraints: { :id => /CONST/ } do resources :bar end 

A nested resource inherits this restriction for its own identifier, so the generated routes will be like this:

 /foo/:foo_id/bar/:id/edit(.:format) {:id=>/CONST/, :foo_id=>/CONST/, :action=>"edit", :controller=>"bar"} 

So, I do not want the "id" parameter of the Bar resource to be limited.

Currently, I just map the routes I want manually, one by one, but I really want to create it as a resource helper. How can i do this?

+6
source share
1 answer

What about:

 resources :foo, constraints: { :id => /CONST/ } resources :foo, constraints: { :foo_id => /CONST/ } do resources :bar end 
+4
source

Source: https://habr.com/ru/post/898440/


All Articles