views:

25

answers:

2

Can someone please explain the following, with example urls? thanks a bundle! (a gem bundle!)

resources :products do
  resource :category

  member do
    post :short
  end

  collection do
    get :long
  end
end

Resources maps all the routes in the ProductController right? How is category embedded?

match 'products/:id', :to => 'catalog#view'

Does this map /products/234 to the categolController, view action?

+4  A: 

Try running rake routes from your Rails project directory. That'll spit out a full list of routes and where they map to.

Chris Heald
+1  A: 

As Chris mentioned rake routes will tell you, but a quick explanation:

any product based routes will go to the products controller so:

GET /products       # products controller index action
GET /products/:id   # products controller show action
POST /products      # products controller create action
PUT /products/:id  # products controller update action
... etc etc

You'll also be given some extra routes however that go to a categories controller, this category will be a property of some product... so:

GET /products/:product_id/category   # categories controller index action
POST /products/:product_id/category  # categories controller create action
... etc etc

If you do something like:

match 'products/:id', :to => 'catalog#view'

you're overriding the default show action of the route. Is this what you want? Likely not. Again, run rake routes to find out what's going on.

brad