# Conditionally loading a particular routes file

**URL:** <https://www.ruby-forum.com/t/conditionally-loading-a-particular-routes-file/117495>\
**Category:** Rails\
**Created:** [October 17, 2007, 11:46am UTC](https://www.ruby-forum.com/t/conditionally-loading-a-particular-routes-file/117495 "2007-10-17T11:46:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tachekent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@tachekent](https://www.ruby-forum.com/u/tachekent)\
**Post date:** [October 17, 2007, 11:46am UTC](https://www.ruby-forum.com/t/conditionally-loading-a-particular-routes-file/117495/1 "2007-10-17T11:46:19Z")

</div>

Hi there,  
I’m trying to use RESTful routes with an application that has 2  
possible URL roots (e.g):

[www.example.com/yournamehere/](http://www.example.com/yournamehere/)  
and

> **[Your Name Here - Domain Name Concierge Services, Coming Soon.](http://www.yournamehere.com/)**
>
> Professional Full Service Concierge for Secure Domain Name Transactions - Leasing, Acquisitions, Co-Branding and Revshares.

(for people who wish to use their own domain name for the app)

with the same application being run for both on a mongrel cluster  
behind apache.

Ideally I wouldn’t have 2 seperate deployments, but currently I can’t  
work out how else to create a routes file that works for both such  
that I can use url\_for throught my app. I have tried adding a  
conditional to the routes file:

if request.env[‘SERVER\_NAME’].include(“[example.com](http://example.com)”)  
prefix = ‘/:artistname’  
else  
prefix = ‘’  
end

and adding the “prefix” variable to the affected routes eg:

map.artist\_cv prefix+‘/cv/:action’, :controller =\>  
‘cv\_items’, :action =\> ‘index’  
map.resources :artworks, :path\_prefix =\> prefix

Unsurprisingly nothing has worked so far! I’m not even sure if it’s  
possible to use a variable like that in a route and I can’t access  
request.env either as it hasn’t been initialised yet.

Can anyone tell me if I’m totally barking up the wrong tree, and if  
they have any better suggestions…  
thanks  
dorian

---

<div class="post-metadata">

**Author:** ![tachekent](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7993a0/32.png) [@tachekent](https://www.ruby-forum.com/u/tachekent)\
**Post date:** [October 18, 2007, 8:40am UTC](https://www.ruby-forum.com/t/conditionally-loading-a-particular-routes-file/117495/2 "2007-10-18T08:40:42Z")

</div>

Yes you are wrong 😛

Try add this to your routes.rb when you deploy inside your document  
root.

ActionController::AbstractRequest.relative\_url\_root = ‘/username’
