# Can't override routing code

**URL:** <https://www.ruby-forum.com/t/cant-override-routing-code/94162>\
**Category:** Rails\
**Created:** [April 23, 2006, 5:18pm UTC](https://www.ruby-forum.com/t/cant-override-routing-code/94162 "2006-04-23T17:18:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@Henrik\_N](https://www.ruby-forum.com/u/Henrik_N)\
**Post date:** [April 23, 2006, 5:18pm UTC](https://www.ruby-forum.com/t/cant-override-routing-code/94162/1 "2006-04-23T17:18:28Z")

</div>

I want to change some of Rails’ routing code so that I can make routes  
subdomain-sensitive.

The code at [Peak Obsession](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.

---

<div class="post-metadata">

**Author:** ![Henrik\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@Henrik\_N](https://www.ruby-forum.com/u/Henrik_N)\
**Post date:** [April 23, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/cant-override-routing-code/94162/2 "2006-04-23T17:38:18Z")

</div>

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.
