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?

Makoto
  • 104,088
  • 27
  • 192
  • 230
davidicus
  • 630
  • 1
  • 6
  • 16
  • Could you give a try to this [`friendly_id`](https://github.com/norman/friendly_id) ? Also look at this [blogpost](http://jasoncodes.com/posts/rails-3-nested-resource-slugs). – Arup Rakshit May 27 '14 at 19:35

1 Answers1

43
resources :imprintables do
  collection do
    resources :styles, :brands, :colors
  end
end
Marek Takac
  • 3,002
  • 25
  • 30