Hi, coderz!! :-) Can somebody help me on that? I try to setup a nested controller for the ''admin'' section of my webapp. I want urls like that: /admin/:action -> AdminController (in folder ''app/controllers'') /admin/products/:action -> Admin::ProductsController (in folder ''app/controllers/admin'') /admin/orders/:action -> Admin::OrdersController (in folder ''app/controllers/admin'') However I would like to _not_ setup a specific route for each new controller if possible. The problem, that comes up, is that a url like: /admin/products will be interpreted by rails as: :controller => "admin", :action => "products" and not :controller => "admin/products" (proper writing ?????), :action => "index" I don''t have any clue, so any help is more than welcome! :-) Best regards Peter
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 29, 2005, at 1:02 AM, Pete wrote:> I try to setup a nested controller for the ''admin'' section of my > webapp. > I want urls like that: > > /admin/:action -> AdminController (in folder ''app/ > controllers'') > /admin/products/:action -> Admin::ProductsController (in folder > ''app/controllers/admin'') > /admin/orders/:action -> Admin::OrdersController (in folder ''app/ > controllers/admin'') > > However I would like to _not_ setup a specific route for each new > controller if possible.Hi Pete, Try using a regexp requirement on :controller map.connect ''admin/:controller/:action/:id'', :requirements => { :controller => /^(products|orders)$/ } map.connect ''admin/:action/:id'', :controller => ''admin'' Just make certain that you don''t make a controller with the same name as an action in your main admin controller. jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDY0G3AQHALep9HFYRApUNAJ9MxT8AbWfzZCnK8//V7t6cw1zRXgCggK5/ GRERyV5iTPW594iDdnqsvpk=Z3V5 -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 29, 2005, at 2:32 AM, Jeremy Kemper wrote:> On Oct 29, 2005, at 1:02 AM, Pete wrote: >> I try to setup a nested controller for the ''admin'' section of my >> webapp. >> I want urls like that: >> >> /admin/:action -> AdminController (in folder ''app/ >> controllers'') >> /admin/products/:action -> Admin::ProductsController (in folder >> ''app/controllers/admin'') >> /admin/orders/:action -> Admin::OrdersController (in folder ''app/ >> controllers/admin'') >> >> However I would like to _not_ setup a specific route for each new >> controller if possible. > > Try using a regexp requirement on :controller > > map.connect ''admin/:controller/:action/:id'', > :requirements => { :controller => /^(products|orders) > $/ } > map.connect ''admin/:action/:id'', > :controller => ''admin''Oops, I realized this won''t work for you since it doesn''t resolve the app/controllers/admin nesting. Also, the second route is superfluous since it''s handled by the default route. Perhaps map.connect '':controller/:action/:id'', :requirements => { :controller => /^admin\/(products|orders)$/ } though this is untested. I''m not sure whether routes will let the / slip by. Hope this was more helpful than hurtful! jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDY0q5AQHALep9HFYRAqWNAKCrr0PHqy4YGdKRA68aVvAiG2ggfgCcDQgD 3kHjo2xyeig/LHrSde2IcZk=Zk+B -----END PGP SIGNATURE-----