Using nested resources without the parent ID in Rails
Asked Answered
C

1

21

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?

Cleaning answered 27/5, 2014 at 19:8 Comment(1)
Could you give a try to this friendly_id ? Also look at this blogpost.Audrey
A
43
resources :imprintables do
  collection do
    resources :styles, :brands, :colors
  end
end
Ancon answered 27/5, 2014 at 20:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.