This project is archived and is in readonly mode.

#2510 ✓invalid
kik

url_for ignores routing priority

Reported by kik | April 16th, 2009 @ 11:55 AM | in 2.3.4

It seems that 'url_for' sometimes ignores routing priority.

I'm using


$ ruby --version
ruby 1.8.6 (2008-08-11 patchlevel 287) [i686-linux]
$ rails --version
Rails 2.1.1

My application is


$ rails myapp
$ cd myapp
$ ./script/generate controller foo/qix index
$ # edit routes.rb and foo/qix_controller.rb

routes.rb


ActionController::Routing::Routes.draw do |map|
  map.connect 'qix/:action/:file.:extname', { :controller => 'foo/qix' }
  map.connect 'qix/:action/:id', { :controller => 'foo/qix' }
  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'
end

foo/qix_controller.rb


class Foo::QixController < ApplicationController
  def index
    logger.debug { url_for :id => 3 }
  end
end

I think this 'url_for' should return "http://localhost:3000/qix/index/3". But, If I access "http://localhost:3000/qix/index/2", it returns "http://localhost:3000/foo/qix/index/3".

Method 'RouteSet#routes_for_controller_and_action_and_keys' returns unstable-sorted result. When I overwrite the method with not sorting version, 'url_for' seems working fine.


module ActionController
  module Routing
    class RouteSet #:nodoc:
      def routes_for_controller_and_action_and_keys(controller, action, keys)
        selected = routes.select do |route|
          route.matches_controller_and_action? controller, action
        end
        selected
      end
    end
  end
end

Comments and changes to this ticket

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>

Attachments

Referenced by

Pages