Using nested resources without the parent ID in Rails
nested-resources, nested-routes, ruby, ruby-on-rails
Solution
resources :imprintables do
collection do
resources :styles, :brands, :colors
end
end
Problem
I have a class called `Imprintables` with nested resources `Styles`, `Brands`, `Colors`, and `Sizes`. I currently have this in my routes file: ``` resources :imprintables do resources :styles, :brands, :colors resources :sizes do collection do post 'update_size_order' end end end ``` Which produces routes like this: ``` /imprintables/:imprintable_id/brands /imprintables/:imprintable_id/colors /imprintables/:imprintable_id/styles /imprintables/:impritnable_id/sizes ``` I don't want to have all my nested resources tied to 1 specific imprintable. I want to have my routes look like: ``` /imprintables/brands /imprintables/styles /imprintables/colors /imprintables/sizes ``` ...etc. Whats the best way to go about this?