REST route not working

I have a nested route that doesn’t want to work for me.

In my routes.rb I have:
/////////////
map.resources :orders, :collection => { :archived => :get, :search =>
:post } do |orders|
orders.resources :shipments, :collection => { :track => :get }
orders.resources :addressbooks, :name_prefix => “order_”
end
/////////////

The problem is, I’m trying to access the track route using:
track_shipment_path(order_id, id)
which would translate to:
/orders/33333/shipments/111;track
but it’s saying undefined method `track_shipment_path’

I’ve accessed the :archived route this way, just can’t understand why
the track route doesn’t work.

Just wondering what I’m doing wrong.

Thanks,

Dave

Hey,

you’ve got ‘track’ defined on the shipments collection so it would be:

track_shipments_path(order_id)

But seeing as the URL you quoted is for a shipments member (/orders/
333/shipments/111;track), you probably want this:

orders.resources :shipments, :member => {:track => :get}

in which case, the helper would be (as you expected)
track_shipment_path(order_id, id)

HTH,
Trevor

Trevor S. wrote:

But seeing as the URL you quoted is for a shipments member (/orders/
333/shipments/111;track), you probably want this:

orders.resources :shipments, :member => {:track => :get}

in which case, the helper would be (as you expected)
track_shipment_path(order_id, id)

HTH,
Trevor

Hi Trevor,

That was exactly what I needed! Thanks.

I’m having a hard time understanding the difference
between a collection and a member. Will figure it out
someday.

Thanks again for your help!

Dave

David C. wrote:

I’m having a hard time understanding the difference
between a collection and a member. Will figure it out
someday.

And that day is the day. I finally read the part of the peepcode rest
cheatsheet that has collections & members on there.

Learn something new everyday.