Ending a Rails 2 URL with an IP address causes routing error?

Posted by Dave Williams on Stack Overflow See other posts from Stack Overflow or by Dave Williams
Published on 2010-05-07T09:33:17Z Indexed on 2010/05/07 9:38 UTC
Read the original article Hit count: 566

Filed under:
|
|
|
|

I'm trying to construct URLs in the format http://servername/find/by/CRITERION/VALUE

CRITERION is a finite set of strings, as is VALUE. Trouble is, VALUE needs to be an IP address in some situations, and it's causing me a routing error.

Here's my route:

  map.find 'find/by/:criterion/:query', :controller => "find", :action => "by"

And the error, from the Mongrel logs:

Processing ApplicationController#index (for 127.0.0.1 at 2010-05-07 10:20:32) [GET]
ActionController::RoutingError (No route matches "/find/by/ip/1.2.3.4" with {:method=>:get}):
Rendering rescues/layout (not_found)

If I visit /find/by/foo/bar or /find/by/foo/1234 I don't have problems. I suspect the problem might be Rails' inference of MIME types based on periods in the URL, but I don't really know how I can disable that. I've tried passing a :defaults => {:format => :html} to the route but that causes Mongrel to fail to start entirely.

Any help appreciated!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about routing