Conditionally loading a particular routes file

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

www.example.com/yournamehere/
and
www.yournamehere.com/
(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”)
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

Yes you are wrong :stuck_out_tongue:

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

ActionController::AbstractRequest.relative_url_root = ‘/username’

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs