Optional routing URL component?

For legacy reasons, I'd like to be able to have part of a url as optional, the problem is that it's at the start of the URL, rather than the end.

/laddr/match/result

with '/laddr' being optional, depending on which URL the user uses to access the site.

Is it possible to do this with routes?

> Is it possible to do this with routes?

of course, everything is possible with RubyonRails, don't make this mistake and ask such a question again :stuck_out_tongue: *just kidding*

heh :slight_smile:

map.connect /:option/match/result, :controller => "something", :action => "methodname", :option => /.*/

Try that :smiley:

Cool, that works, in most cases. Just need to figure out the accompanying apache rewrite rules to serve any actual files from te directory, instead of pointing them at mongerl.

Cheers Jamal ...

So, while this works great on the productions server (Apache2 + mongrel_cluster) it causes a few problems when running on the dev machine.

Can I have a seperate set of routes for the dev box? or am I missing something?

This is what is surrently in my routes.rb :

  map.connect '/:option', :controller => "welcome", :option => /laddr/

  map.connect '/:option/:action/:defender_id/ ladder/:ladder_id', :controller => 'ladder', :option => /laddr/   map.connect '/:option/match/refuse/:id', :controller => 'match', :action => 'refuse', :option => /laddr/   map.connect '/:option/match/result/:id', :controller => 'match', :action => 'result', :option => /laddr/   map.connect '/:option/match/:match_id/:action/:id', :controller => 'match', :option => /laddr/

  # Install the default route as the lowest priority.   map.connect '/:option/:controller/:action/:id.:format', :option => / laddr/   map.connect '/:option/:controller/:action/:id', :option => '/laddr/'

The optional bit, doesn't seem to be optional, so if I do http://localhost:3000/ I get an error :

"no route found to match "/" with {:method=>:get}"

but when I add the /laddr it works fine. I can live with that, but it also breaks static files, stylesheets and images for example, as it's now looking for those in /laddr/stylesheets

I don't really like the idea of having 2 sets of routes, because, well, I only want to maintain 1 and not forget about the production ones all the time (because you know that's what will happen).

-S

I'm still stuck with this if anyone has any ideas?