views:

30

answers:

1

I have several urls declared in the routes.rb, such as

aaa/index.html aaa/bbb.html

bbb/index.html bbb/ccc/index

so it looks like a non-rails site.

I want it so that when a user accesses

aaa/ or bbb/ccc/ they would automatically be redirected to the action routed to the index.html of the corresponding directory.

currently I am writing an additional entry to the routes.rb, for ex

aaa/index.html :controller=> 'aaa', :action => 'index' aaa/ :controller=> 'aaa', :action => 'index'

but find it quite redundant to do so.

Is there a more elegant way to do this?

+1  A: 

First, I don't know why you are coercing the router to do these sorts of thing, but since you asked I am guessing you could do something like:

['aaa', 'bbb/ccc', etc. etc.].each do |path|
  map.connect path, :controller => path.match(/\/(.+)/)[1], :action => 'index'
end
bobbywilson0