Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

: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 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?

like image 691
Evan Avatar asked Jun 08 '10 16:06

Evan


People also ask

How many types of routes are there in Rails?

Rails RESTful Design which creates seven routes all mapping to the user controller. Rails also allows you to define multiple resources in one line.

How do I see all Rails routes?

TIP: If you ever want to list all the routes of your application you can use rails routes on your terminal and if you want to list routes of a specific resource, you can use rails routes | grep hotel . This will list all the routes of Hotel.

How do routes work in Rails?

Rails routing is a two-way piece of machinery – rather as if you could turn trees into paper, and then turn paper back into trees. Specifically, it both connects incoming HTTP requests to the code in your application's controllers, and helps you generate URLs without having to hard-code them as strings.


1 Answers

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

like image 143
Jamie Wong Avatar answered Sep 30 '22 12:09

Jamie Wong