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

I am trying to create urls in the format http: // servername / find / by / CRITERION / VALUE

CRITERION is a finite set of rows equal to VALUE. The problem is that VALUE must be an IP address in some situations, and this causes me a routing error.

Here is 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 find / find / by / foo / bar or / find / by / foo / 1234 I have no problem. I suspect the problem may be with Rails inferring MIME types based on periods in the URL, but I really don't know how this can be disabled. I tried passing the route: defaults => {: format =>: html}, but this causes Mongrel to not start completely.

Any help appreciated!

+4
source share
1 answer

Routing route worked!

Now my route:

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

This puts all of the following / find / by / in Array, params [: query], a single URL segment for an array object. For the query / find / by / ip / 1.2.3.4, it looks like this:

 ["ip", "1.2.3.4"] 

Therefore, I can simply refer to the parameters [: query] [0] and the parameters [: query] [1].

If anyone has a better way to do this, post it!

+5
source

Source: https://habr.com/ru/post/1309088/


All Articles