6

It you define constraint on "id" in parent resource:

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

The nested resource will inherits that constraint for its own id, thus the generated routes will be like:

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

So, I don't want the "id" parameter of Bar resource to be that restricted.

Currently, I've just map the routes I want manually, one by one, but I am really want to generate it by resources helper. How can I do that?

senotrusov
  • 799
  • 1
  • 7
  • 7

1 Answers1

4

How about :

resources :foo, constraints: { :id => /CONST/ }
resources :foo, constraints: { :foo_id => /CONST/ } do
  resources :bar
end
charlysisto
  • 3,700
  • 17
  • 30
  • Maybe it will work, but I don't like to repeat the line "resources :foo" – senotrusov Nov 10 '11 at 07:05
  • This is highly unfortunate, but it worked for me... I also applied `only: []` to the second definition to make it clear which `resources` call was routing what. – bloudermilk Jun 17 '12 at 03:00