davidicus
davidicus

Reputation: 649

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?

Upvotes: 21

Views: 4867

Answers (1)

Marek Takac
Marek Takac

Reputation: 3038

resources :imprintables do
  collection do
    resources :styles, :brands, :colors
  end
end

Upvotes: 43

Related Questions