:any option for rails 3 routes
In rails 2 you can use the :any option to define a custom route that responds to any request met开发者_StackOverflowhod 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?
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
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).
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..
精彩评论