Skip to content

Commit

Permalink
Use :namespace instead of :path_prefix for finding controller. [#544
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
tarmo authored and NZKoz committed Jul 24, 2008
1 parent 82f3386 commit 8887f20
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions actionpack/lib/action_controller/routing/builder.rb
Expand Up @@ -67,10 +67,9 @@ def divide_route_options(segments, options)
options = options.dup

if options[:namespace]
options[:controller] = "#{options[:path_prefix]}/#{options[:controller]}"
options[:controller] = "#{options.delete(:namespace).sub(/\/$/, '')}/#{options[:controller]}"
options.delete(:path_prefix)
options.delete(:name_prefix)
options.delete(:namespace)
end

requirements = (options.delete(:requirements) || {}).dup
Expand Down
20 changes: 20 additions & 0 deletions actionpack/test/controller/routing_test.rb
Expand Up @@ -1983,6 +1983,26 @@ def test_namespaced_root_map
Object.send(:remove_const, :Api)
end

def test_namespace_with_path_prefix
Object.const_set(:Api, Module.new { |m| m.const_set(:ProductsController, Class.new) })

set.draw do |map|

map.namespace 'api', :path_prefix => 'prefix' do |api|
api.route 'inventory', :controller => "products", :action => 'inventory'
end

end

request.path = "/prefix/inventory"
request.method = :get
assert_nothing_raised { set.recognize(request) }
assert_equal("api/products", request.path_parameters[:controller])
assert_equal("inventory", request.path_parameters[:action])
ensure
Object.send(:remove_const, :Api)
end

def test_generate_finds_best_fit
set.draw do |map|
map.connect "/people", :controller => "people", :action => "index"
Expand Down

0 comments on commit 8887f20

Please sign in to comment.