This project is archived and is in readonly mode.

#2862 ✓invalid
Steven Hartland

Possible routing bug

Reported by Steven Hartland | July 2nd, 2009 @ 10:53 AM | in 2.x

When a catch all route for a specific method is configured and an invalid URL is requested instead of the expected ActionController::RoutingError we're seeing ActionController::MethodNotAllowed

An example of this is:
map.connect '*path', :controller => 'fixes', :action => 'options_for_mopd', :conditions => { :method => :options }

It seems that the conditions check is being done too late so instead of matching on the combination of the path and conditions instead its matching on the path and then checking the conditions, resulting in what I believe is an incorrect exception.

Comments and changes to this ticket

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) July 2nd, 2009 @ 06:18 PM

    • State changed from “new” to “invalid”

    Rails specifically raises a MethodNotAllowed in this case to mirror the HTTP error codes http://en.wikipedia.org/wiki/List_of_HTTP_status_codes specifically, 405

  • Steven Hartland

    Steven Hartland July 2nd, 2009 @ 09:15 PM

    I would be inclined to agree for a none wild card path, but with the current behaviour is impossible to catch the total wild card case for a specific method request, without effectively breaking standard 404 behaviour for the instance.

    It may be that an additional directive to the route, possibly within :conditions, could be used to indicate if a match to the rule but not the method should result in NotFound or MethodNotAllowed.

    An example of this could be:
    map.connect '*path', :controller => 'fixes', :action => 'options_for_mopd', :conditions => { :method => :options, :match_method => true }

    Either way it would be a good idea to make it clear in the docs of ActionController::Routing as the current statement:
    "With conditions you can define restrictions on routes." Indicates that conditions "restrict" the matching of a route, which is not the case; the route matches but is bypassed in a post filter by the condition, hence facilitating MethodNotAllowed / 405 functionaility, if the path matches but the method does not.

    For completeness if anyone reading this is looking for a workaround, you can do this by adding a second catch all route without a :method condition that generates 404 e.g
    map.nofile '*path', :controller => 'fixes', :action => 'do404'

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages