Rails routes matching query parameters

Posted by Harry Wood on Stack Overflow See other posts from Stack Overflow or by Harry Wood
Published on 2010-05-11T13:30:38Z Indexed on 2010/05/11 13:34 UTC
Read the original article Hit count: 252

Filed under:
|

Rails routes are great for matching RESTful style '/' separated bits of a URL, but can I match query parameters in a map.connect config. I want different controllers/actions to be invoked depending on the presence of a parameter after the '?'.

I was trying something like this...

map.connect "api/my/path?apple=:applecode", :controller => 'apples_controller', :action => 'my_action'

map.connect "api/my/path?banana=:bananacode", :controller => 'bananas_controller', :action => 'my_action'

For routing purposes I don't care about the value of the parameter, as long as it is available to the controller in the 'params' hash

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about routes