# Route Collections and HTTP methods

**URL:** <https://www.ruby-forum.com/t/route-collections-and-http-methods/159046>\
**Category:** Rails\
**Created:** [January 30, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/route-collections-and-http-methods/159046 "2009-01-30T19:47:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [January 30, 2009, 7:47pm UTC](https://www.ruby-forum.com/t/route-collections-and-http-methods/159046/1 "2009-01-30T19:47:15Z")

</div>

I don’t see a way to create a single URL in a collection and then have  
routing dispatch to the appropriate method based on the HTTP method.

map.resources :packages, :collection=\>{ :search=\>:get }

Gets me half way there, but I can see a way to say that I want the  
POST to go to the do\_search method.

Furthermore

map.resources :packages, :collection=\>  
{ :search=\>:get, :do\_search=\>:post }

results in a ActionController::MethodNotAllowed for POSTs to /packages/  
do\_search.

`rake routes` affirms that this should be accepted:

do\_search\_packages POST /packages/do\_search  
{:action=\>“do\_search”, :controller=\>“packages”}

How can I solve either of these?  
Thanks

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [January 30, 2009, 9:44pm UTC](https://www.ruby-forum.com/t/route-collections-and-http-methods/159046/2 "2009-01-30T21:44:07Z")

</div>

Hi,

I don’t have a solution for you but in general searches are GET and  
never POST. I don’t know where this nonsense comes from but  
it’s breaking the principles behind the HTTP.

Did you try :any instead of :post ?

ciao, tom

---

<div class="post-metadata">

**Author:** ![MaggotChild](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7ea924/32.png) [@MaggotChild](https://www.ruby-forum.com/u/MaggotChild)\
**Post date:** [January 30, 2009, 10:16pm UTC](https://www.ruby-forum.com/t/route-collections-and-http-methods/159046/3 "2009-01-30T22:16:56Z")

</div>

> …but in general searches are GET and  
> never POST. I don’t know where this nonsense comes from but  
> it’s breaking the principles behind the HTTP.

Well I don’t disagree with this paradigm, but the point is Rails seems  
to not allow one to set up a route like the defaults provided by  
map.resourses. i.e one URL, dispatched to to 2 different actions based  
on HTTP method.

> Did you try :any instead of :post ?

Either one raises the nonsensical ActionController::MethodNotAllowed.  
I say nonsensical because rake routes tells me do\_search accepts  
posts.
