Forum: Ruby on Rails routes limitations : trailing / and more dynamic rules

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Eric D. (Guest)
on 2005-11-29 19:19
Hello all,

I've two limitations in rails routes for which I don't find a solution.

1. how to distinguish /hello/ from /hello ?
Rails routes seem not use nor validate the trailing slash. routes
'hello' and 'hello/' both validates urls '/hello' and '/hello/'

2. how to have a dynamic 'internal' part in the url ?
I would like to match everithing like %r{/\.ht} so that the following
routes are catch : /.htaccess /.htusers
(I know that apache is already forbidding this ones, it is only an
Rails routes let me write ':special_with_regexp/*path_info' but not
'*path_info/:special_with_regexp'. Is there a way to do that ?
It seems I can't even do a regexp requirement on the *path_info to check
all this by hand (at least I didn't manage to do it).

From what I see rails routes as pretty limited. Is there a way to
resolve my two needs ? If not, is there at least a (simple) way to take
hand on routes to do 'by hands regexp' on the full url ?
It seems that rails routes are more restricted and not very simpliers
than plain regexp for my personnal needs.

And ... maybe two ideas for feature request :

3. It would be cool if a could chain some routes. Say that "ok, url
begin with /hello so put it in pipe A to finish dispatching", "this one
is not /hello but /foo, so finish dispatching with pipe B". Something
like sub-route.
something like :
map.connect_with_submap 'hello/*path_info' { |sub|
    sub.connect 'foo/:controller/:action', ...   # to check url
    sub.connect 'bar/:controller/:action', ...   # to check url

4. I would be very convenient to be able to add a block to do
additionnal checks by hands if the regexp is ok. Maybe something like :
# validates only if :id is a multiple of 2
map.connect ':controller/:action/:id',
            :requirements => {:id => /\d+/}} ,
            { |request, params| 0 == id % 2 }

Thanks in advance for any reply or idea.

Eric D.
This topic is locked and can not be replied to.