# Routes With Same URL Mapped To Different Actions

**URL:** <https://www.ruby-forum.com/t/routes-with-same-url-mapped-to-different-actions/175229>\
**Category:** Rails\
**Created:** [September 10, 2009, 1:08am UTC](https://www.ruby-forum.com/t/routes-with-same-url-mapped-to-different-actions/175229 "2009-09-10T01:08:00Z")\
**Posts on this page:** 2\
**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:** [September 10, 2009, 1:08am UTC](https://www.ruby-forum.com/t/routes-with-same-url-mapped-to-different-actions/175229/1 "2009-09-10T01:08:00Z")

</div>

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.

---

<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:** [September 10, 2009, 2:14am UTC](https://www.ruby-forum.com/t/routes-with-same-url-mapped-to-different-actions/175229/2 "2009-09-10T02:14:46Z")

</div>

On Sep 9, 2009, at 7:06 PM, MaggotChild wrote:

> 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

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
