views:

200

answers:

3

In rails 2 you can use the :any option to define a custom route that responds to any request method e.g.

map.resources :items, :member => {:erase => :any}

rails 3 doesn't seem to support the :any option

resources :items do
  get :erase, :on => :member # works
  any :erase, :on => :member # doesn't work
end

does anyone know if this option has been removed or just renamed?

A: 

Good question.

Looking at the Edge Rails routing guide and the Rails 3 source it doesn't look like it's supported. You could raise a ticket in the Rails Lighthouse (I couldn't find an existing one for this).

John Topley
+1  A: 

From digging around and seeing what the get, post, put, and delete actions actually do in ActionDispatch, I think all you need to do is match. So:

resources :items do
  get :erase, :on => :member
  match :erase, :on => :member
end

I don't think that syntax for match is actually documented, but the routes it constructs are, atleast for me, what you'd expect from an all method

Jamie Wong
Additionally, you can (ostensibly) specify methods with the :via specification (:via => [ :any, :get, :put, :post, :delete ]); so far as I can tell, :any does not work (oddly nil seems to, although the routing table will then show a blank instead of ANY), but leaving out :via equates to :any.
Asher
A: 

Match will work, but not inside a resources definition unfortunately. I rather wish they'd bring back a way to define get/post at least together..

Kevin
Hmm? It worked just fine for me inside the resources block. Using Rails 3.0.0.beta4
Jamie Wong
Aah - my problem was :on => :member. I was using my resource name (:on => :item).The error message isn't very good apparently.."/Library/Ruby/Gems/1.8/gems/actionpack-3.0.0.beta4/lib/action_dispatch/routing/mapper.rb:738:in `match': can't define route directly in resource(s) scope (ArgumentError)"
Kevin