# Routing conditions only affect recognition, not URL generati

**URL:** <https://www.ruby-forum.com/t/routing-conditions-only-affect-recognition-not-url-generati/88672>\
**Category:** Rails\
**Created:** [March 13, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/routing-conditions-only-affect-recognition-not-url-generati/88672 "2007-03-13T13:45:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [March 13, 2007, 1:45pm UTC](https://www.ruby-forum.com/t/routing-conditions-only-affect-recognition-not-url-generati/88672/1 "2007-03-13T13:45:07Z")

</div>

I am hitting a problem where it seems that URL “:conditions=\>” correctly  
affect URL recognition, but don’t affect URL generation.

Basically I have two very similar websites which differ slightly in how  
they are laid out, but have substantially similar code. I want to use a  
bit of routing magic to use a single codebase for both sites. Note: I  
use the request\_routing plugin to get access to the URL as a condition

eg:

```
map.with_options( :conditions => { :domain => /(^|\.)blog\./ } ) do

```

|blog|  
…  
end

```
map.with_options( :conditions => { :domain => /(^|\.)track\./ } ) do

```

|track|  
…  
end

What happens is that at the “track” site the URLs work correctly if I  
type them in manually to the browser, ie they get recognised correctly,  
but new URLs are all generated in the scheme for the “blog” site  
(because it comes higher up in routing order - if I reverse the routes  
then the reverse situation occurs)

How can I get my :conditions to take effect during URL generation as  
well as recognition. Examining action\_controller/routing.rb isn’t  
trivial…

Suggestions please…

Ed W

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [March 15, 2007, 2:17am UTC](https://www.ruby-forum.com/t/routing-conditions-only-affect-recognition-not-url-generati/88672/2 "2007-03-15T02:17:48Z")

</div>

Ed,  
I’ve been asking this same question for the last month and keep  
getting doors slammed in my face. Mostly, “read the book” type  
response (of which I’ve read most of them) and there’s no mention of  
this.  
I think the secret is keeping all of the HTML ‘wording’ that the user  
see and have it read in from the database on all sites.  
I’m easily reachable if you’d like to discuss this sometime.  
BraveDave

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [March 15, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/routing-conditions-only-affect-recognition-not-url-generati/88672/3 "2007-03-15T16:07:39Z")

</div>

Have you two read the routing articles on Jamis B.s’ site?  
[Buckblog: Category: under the hood](http://weblog.jamisbuck.org/under-the-hood) I think you’ll find a good  
bit of  
information there that’d help out. Specifically the routing\_tricks  
plugin  
that Jamis developped. I use it on one of my apps and it’s a godsend.

RSL
