views:

26

answers:

2
map.resource  :basket, :collection => { :checkout => :post }

The above does not work for a resource, as you would expect since basket is a resource (ie. singular) not resources, so there is no concept of a collection, everything should be scoped to the current_user. In this case User has_one Basket.

However I would like to specify a custom route without having to resort to adding another line in routes, eg:

map.checkout 'basket/checkout', :controller => 'baskets', :action => 'checkout'

Is this possible?

Of course my other option is to add a checkouts controller.

A: 

Just use :member option instead of :collection:

map.resource :basket, :member => {:checkout => :post}
lest
+1  A: 

If the basket is scoped to the user I'd make it a nested resource:

map.resources :users do |users|
  users.resource :basket, :member => { :checkout => :post }
end

... or in Rails 3 ...

resources :users do
  resource :basket do
    post :checkout, :on => :member
  end
end

This way you'll be able to scope the basket to the user who's checking out. The URL will end up looking like this:

/users/5/basket/checkout

You also get the nicely worded named route 'checkout_user_basket'.

Nicholas C