public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Use :namespace instead of :path_prefix for finding controller. [#544 
state:resolved]

:namespace is supposed to be the module where controller exists.
:path_prefix can contain anything, including variables, which
makes it unsuitable for determining the module for a controller.

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Tarmo Tänav (author)
Thu Jul 03 07:49:12 -0700 2008
lifo (committer)
Thu Jul 03 08:11:50 -0700 2008
commit  a37d065f85941e1fe746dff4d42f015e1618834f
tree    2e498068f1ec02c083150c2471243c5114bf3b1d
parent  d20e8dd2207a848e2712c19ad38d6abb6f98ca07
...
67
68
69
70
 
71
72
73
74
75
76
...
67
68
69
 
70
71
72
 
73
74
75
0
@@ -67,10 +67,9 @@ module ActionController
0
         options = options.dup
0
 
0
         if options[:namespace]
0
-          options[:controller] = "#{options[:path_prefix]}/#{options[:controller]}"
0
+          options[:controller] = "#{options.delete(:namespace).sub(/\/$/, '')}/#{options[:controller]}"
0
           options.delete(:path_prefix)
0
           options.delete(:name_prefix)
0
-          options.delete(:namespace)
0
         end
0
 
0
         requirements = (options.delete(:requirements) || {}).dup
...
2039
2040
2041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2042
2043
2044
...
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
0
@@ -2039,6 +2039,26 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
0
       Object.send(:remove_const, :Api)
0
     end
0
 
0
+    def test_namespace_with_path_prefix
0
+      Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })
0
+
0
+      set.draw do |map|
0
+
0
+        map.namespace 'api', :path_prefix => 'prefix' do |api|
0
+          api.route 'inventory', :controller => "products", :action => 'inventory'
0
+        end
0
+
0
+      end
0
+
0
+      request.path = "/prefix/inventory"
0
+      request.method = :get
0
+      assert_nothing_raised { set.recognize(request) }
0
+      assert_equal("api/products", request.path_parameters[:controller])
0
+      assert_equal("inventory", request.path_parameters[:action])
0
+    ensure
0
+      Object.send(:remove_const, :Api)
0
+    end
0
+
0
     def test_generate_finds_best_fit
0
       set.draw do |map|
0
         map.connect "/people", :controller => "people", :action => "index"

Comments