This project is archived and is in readonly mode.
strange link_to behavior on links to controllers in modules
-
Amol Hatwar (rubygem)
Attached test patch that confirms the said behavior...
-
Amol Hatwar (rubygem)
If someone can confirm that this indeed is a *bug*, maybe I can work towards a patch that fixes it...
-
nikz
- Tag set to helper
Hey Amol,
The relevant code is in /actionpack/lib/action_controller/routing.rb on line 348:
# Returns a controller path for a new +controller+ based on a +previous+ controller path. # Handles 4 scenarios: # # * stay in the previous controller: # controller_relative_to( nil, "groups/discussion" ) # => "groups/discussion" # # * stay in the previous namespace: # controller_relative_to( "posts", "groups/discussion" ) # => "groups/posts" # # * forced move to the root namespace: # controller_relative_to( "/posts", "groups/discussion" ) # => "posts" # # * previous namespace is root: # controller_relative_to( "posts", "anything_with_no_slashes" ) # =>"posts" # def controller_relative_to(controller, previous) if controller.nil? then previous elsif controller[0] == ?/ then controller[1..-1] elsif %r{^(.*)/} =~ previous then "#{$1}/#{controller}" else controller end end endFrom that, it looks the current behaviour is intended. Perhaps bring up a discussion on the mailing list?
Also, just by the bye, your test fails for me, but not for the reason you describe. The first link_to call just generates "http://example.com", rather than a route at all. (That's on the latest edge rails).
-
nikz
Actually, upon further investigation, that method isn't called anywhere! (nowhere I can grep for, anyways).
Regardless, the REAL (slim shady) relevant section is in route_set.rb (line 322).
# if the controller has changed, make sure it changes relative to the # current controller module, if any. In other words, if we're currently # on admin/get, and the new controller is 'set', the new controller # should really be admin/set. if !named_route && expire_on[:controller] && options[:controller] && options[:controller][0] != ?/ old_parts = recall[:controller].split('/') new_parts = options[:controller].split('/') parts = old_parts[0..-(new_parts.length + 1)] + new_parts options[:controller] = parts.join('/') endLooks like the intended behaviour is what you're seeing :)
Maybe someone can close this ticket?
-
Pratik
- State changed from new to invalid
