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 likelocalhost:3000/document_managers/A/1orlocalhost:3000/document_managers/B/221/1orlocalhost:3000/document_managers/C/121/1but that not the case even though
localhost:3000/document_managers/D/121/1is treated as valid url
and module is set to D even though the “D” is not in listed array
above -
I want the the URL
localhost:3000/document_managers/Ato
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/1then 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 aroutesI don’t know why as I have already
ActionController::UnknownAction
defined the controller and action.
In Rails 3.1, you can do this in your routes file to get what you want: