Hi, since upgrading to rails 0.13.x the following kind of route does not seem to work anymore: map.connect ":controller/:vkid/:action/:id", :requirements => {:controller => /^vk\/.+$/ } The idea is to apply this route only to controllers in the "Vk" module. This worked for sure in previous versions of rails. Unfortunately, routes does not have a very good documentation that specifies the behaviour, more a kind of "documentation by example". So I was wondering if this is a bug or a feature? :) If it''s a bug I might develop a patch, just wanted to make sure it stands a chance of getting accepted... I got around this problem, by creating a route for every controller like this, but it''s a little bit clumsy. # vk_controller_names is computed by inspecting the "app/controllers/vk" directory vk_controller_names.each do |c| map.connect "vk/#{c}/:vkid/:action/:id", :controller => "vk/#{c}" end BTW, I looked at the new routes code. This code generation is pretty cool (and makes a nice speed-up I assume), but it''s kind of tough to read/debug the code. Sebastian
Hi Sebastian, I did not have enough time to implement that feature for 0.13.1, so it was left out. That said, it would be a good idea to add it back, and it will probably be quite easy. If you would be so kind as to create a ticket on Trac, and (perhaps?) upload some unit-tests, I''ll implement it when I get a chance. Please do assign the ticket to me. (aka Ulysses)> BTW, I looked at the new routes code. This code generation is pretty > cool (and makes a nice speed-up I assume), but it''s kind of tough to > read/debug the code.Yes, it can be somewhat troublesome. A good first step is to use script/console to do irb> (code = ActionController::Routing::Routes.write_generation) && nil irb> File.open(''/tmp/generated_code.rb'', ''w'') {|f| f.write(file)} Then you can open the generated source and check it out. You can also sed s/def self/def ActionController::Routing::Routes/ and then use load(''/tmp/generated_code.rb'') to test any hand made changes you make. HTH, Cheers, Nicholas Seckar
Hi Nicholas, Nicholas Seckar wrote:>I did not have enough time to implement that feature for 0.13.1, so it >was left out. That said, it would be a good idea to add it back, and >it will probably be quite easy. > >If you would be so kind as to create a ticket on Trac, and (perhaps?) >upload some unit-tests, I''ll implement it when I get a chance. > > >well, I got some spare time and was curious to lern a bit more about routes, so I wrote a patch myself. I''ve uploaded it as ticket #1917. Hope you like it :) While working on this, I got some headache on how to handle default values for :controller components. I guess its best to not allow them (they are not supported right now, regardless of my patch), but one could construct a contrived example like the following: map.connect ''foo/:controller/:action/:id'', :controller => ''admin/user'', :require => {:controller => /admin\/.+} This route should match ''/foo'' (to Admin::UserController) as well as ''/foo/admin/group'', but not ''/foo/content''. If we want to support this, I could try to develop a patch, but I think it''s not worth the hassle. Note, that the following works right now (.e.g. if no ":controller" is present in the path): map.connect ''foo/:action/:id'', :controller => ''foo/content'' So, the rules about :controller components would be something like this: * if no ":controller" component is in the path, the controller can (or must) be set explicitly by a :controller => string_literal option. * if there is a ":controller" component, it can be restricted via a regexp, but a default value may not be given. Does this make sense? What do you think? Sebastian