Routes With Same URL Mapped To Different Actions

Can't find the answer to this. My old message received no responses (subject was messed up).

Is it possible to create routes that have the same URL yet map to a different action based on the HTTP method (or pseudo method) like a Rails' resource?

For example:

map.resources :foo, :collection => { :purge => :get, :purge_them => :post }

I'd like to use /foo/purge for both actions, and have the appropriate controller method called based on the HTTP request's method -like /foo does for the create and index methods, amongst others.

map.connect('/foo/purge', :controller => 'foo', :action => 'purge' , :conditions => { :method => :get })   map.connect('/foo/purge', :controller => 'foo', :action => 'purge_them', :conditions => { :method => :post})   map.resources :foo

I put parentheses in so the wrapping doesn't kill the syntax.

Since there is an implied precedence based on appearance, if the map.resources(:foo) comes first, GET /foo/purge, looks like you want to show the Foo with id='purge'. (I'm not sure, but a POST /foo/purge might do the FooController#purge_them in either case).

I hope that helps.


Rob Biedenharn