# Handling URL parameters with routes

**URL:** <https://www.ruby-forum.com/t/handling-url-parameters-with-routes/192478>\
**Category:** Rails\
**Created:** [July 30, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/handling-url-parameters-with-routes/192478 "2010-07-30T22:34:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [July 30, 2010, 10:34pm UTC](https://www.ruby-forum.com/t/handling-url-parameters-with-routes/192478/1 "2010-07-30T22:34:29Z")

</div>

Hi,

Rails 2.3.4  
Ruby 1.8.7

I’m having trouble handling parameters in routes. I want to be able to  
handle “?x=1&y=2” style url parameters.

# Here’s the route:

map.connect “schools/list/:country/:province/:city”,  
:controller =\> “schools”,  
:action =\> “list”,  
:country =\> nil,  
:province =\> nil,  
:city =\> nil

# This works:

> > rs.recognize\_path “/schools/list/US”  
> > =\> {:controller=\>“schools”, :action=\>“list”, :country=\>“US”}

# This doesn’t - why not?

rs.recognize\_path “/schools/list?country=US”

ActionController::RoutingError: No route matches “/schools/list?  
country=US” with {}  
from /home/dberger/Repositories/globe\_village/vendor/rails/  
actionpack/lib/action\_controller/routing/recognition\_optimisation.rb:  
66:in `recognize\_path’

I guess I thought Rails handled url parameters automatically. No?

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [July 31, 2010, 7:37am UTC](https://www.ruby-forum.com/t/handling-url-parameters-with-routes/192478/2 "2010-07-31T07:37:17Z")

</div>

Hi,

You need to mention that as a separate route.  
Just add this additional line in your routes…

map.connect “schools/list/:country/:province/:city”,  
:controller =\> “schools”,  
:action =\> “list”,  
:country =\> nil,  
:province =\> nil,  
:city =\> nil

map.connect “schools/list”, :controller =\> “schools”, :action =\> “list”

regards,  
Sur  
[http://rubyonrailshacks.com](http://rubyonrailshacks.com)
