Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nested resources without the parent ID in Rails

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?

like image 991
davidicus Avatar asked May 27 '14 19:05

davidicus


1 Answers

resources :imprintables do
  collection do
    resources :styles, :brands, :colors
  end
end
like image 52
Marek Takac Avatar answered Sep 21 '22 11:09

Marek Takac