I want to change some of Rails' routing code so that I can make routes subdomain-sensitive. The code at http://wiki.rubyonrails.com/rails/pages/RoutingSubdomains works fine when I edit the file (in my case, C:\Program\Ruby\lib\ruby\gems\1.8\gems\actionpack-1.12.1\lib\action_controller\routing.rb) directly. Changing that file seems very fragile, so I figured I would override the method in question in environment.rb instead. However, it seems my routing code is never used for routing... I added this to the end of environment.rb and rebooted the server: class ActionController::Routing::RouteSet def recognize(request) "some text for testing" end end Now, if I do this in some view, I get the output "some text for testing": DEBUG: <%=ActionController::Routing::RouteSet.new.recognize(:foo)%> but the new RouteSet#recognize method is obviously not being used for actual routing, since the routing keeps on working. If I change the method directly in routing.rb to simply return "some text for testing", routing breaks completely. Again, could anyone please tell me what I'm doing wrong, and how to fix it? I suppose a workaround would be to include Rails in the lib directory and modify that, but that's still a lot uglier than just modifying that one method.
on 2006-04-23 17:18
on 2006-04-23 17:38
Henrik N wrote: > I want to change some of Rails' routing code so that I can make routes > subdomain-sensitive. > ... Solved it myself. I simply needed to include alias :recognize! :recognize in my modification, since routing apparently uses recognize! rather than recognize internally, and since overriding the method apparently means any aliases need overriding as well.