Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Nested resource routes inherits parent constraints, how to avoid it?

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?

like image 611
senotrusov Avatar asked Oct 01 '11 12:10

senotrusov


1 Answers

How about :

resources :foo, constraints: { :id => /CONST/ }
resources :foo, constraints: { :foo_id => /CONST/ } do
  resources :bar
end
like image 138
charlysisto Avatar answered Nov 14 '22 17:11

charlysisto