Is there a way to avoid having to do this…
resources :parents do
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
I thought it would be possible to just do this…
resources :parents do
resources :children do
end
resources :children do
collection do
get "/search/:term/:offset/:limit.:format", :action => "search", :constraints => { :term => /\w+/, :offset => /\d+/, :limit => /\d+/ }
end
end
The reason being is I want to be able to use both of these routes…
/children/search/term/0/10
/parents/1/children/search/term/0/10
This seems to do the trick
:parent_idwill be set inparamsif the route throughparenthas been used. Otherwise it won’t be present. I have omitted constraints for clarity. Also you probably should make the.formatoptional.