Using github like chain routes in rails
I have URLs similar to this:
'localhost:3000/document_managers/[:module_name]'
'localhost:3000/document_managers/[:module_name]/1/2/3/.' # can be any level deep
Here is the route definition for them:
map.connect '/document_managers/:module',
:controller => "document_managers",
:action => :new_tree,
:module => ["A","B","C"]
map.connect '/docuemnt_managers/:module/*path',
:controller => "document_managers",
:action => "new_tree",
:module => ["A","B","C"]
Here is the problem:
The idea that module name value can't be anything except from the given above array i.e("A","B","C") like at any time the URL must be something like
localhost:3000/document_managers/A/1
orlocalhost:3000/document_managers/B/221/1
orlocalhost:3000/document_managers/C/121/1
but that not the case even though
localhost:3000/document_managers/D/121/1
is treated as valid url and module is set to D even though the "D" is not in listed array aboveI want the the URL
localhost:3000/document_managers/A
to also redirect to same action i.e new_tree if the extra parameter isn't provided as in the URL contain extra parameters
localhost:3000/document_managers/C/121/1
then the URL is redirected appropriately to the desired controller and action but if the URL only contain the path until the module name the Rails return aroutes ActionController::UnknownAction
I don't know why as I have already defined the controller and action.
In Rails 3.1, you can do this in your routes file to get what you want: