public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
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>

Conflicts:

  actionpack/test/controller/routing_test.rb
Signed-off-by: Michael Koziarski <michael@koziarski.com>
tarmo (author)
Thu Jul 24 03:30:28 -0700 2008
NZKoz (committer)
Thu Jul 24 03:32:50 -0700 2008
commit  8887f2076a52a160bf8c852b5cd04ea588eaa46b
tree    9eaa701d7c07fb83b494c80e1021cd589c0a6f4c
parent  82f338635fd908b40b7adf0328e3041b961109dc
...
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
...
1983
1984
1985
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1986
1987
1988
...
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
0
@@ -1983,6 +1983,26 @@ class RouteSetTest < Test::Unit::TestCase
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

    No one has commented yet.