From 44a10a2440640edae5a39a0be562093503dc7bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 17 Jan 2010 16:18:14 +0100 Subject: Fix resources_path_names branch which was sending an array as entity. [#3715 status:resolved] --- actionpack/lib/action_dispatch/routing/mapper.rb | 59 ++++++++++-------------- 1 file changed, 25 insertions(+), 34 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 9aaa4355f2..811c287355 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -418,28 +418,12 @@ module ActionDispatch def resource(*resources, &block) options = resources.extract_options! - if resources.length > 1 - raise ArgumentError if block_given? - resources.each { |r| resource(r, options) } - return self - end - - if path_names = options.delete(:path_names) - scope(:resources_path_names => path_names) do - resource(resources, options) - end + if verify_common_behavior_for(:resource, resources, options, &block) return self end resource = SingletonResource.new(resources.pop, options) - if @scope[:scope_level] == :resources - nested do - resource(resource.name, options, &block) - end - return self - end - scope(:path => resource.name.to_s, :controller => resource.controller) do with_scope_level(:resource, resource) do yield if block_given? @@ -459,28 +443,12 @@ module ActionDispatch def resources(*resources, &block) options = resources.extract_options! - if resources.length > 1 - raise ArgumentError if block_given? - resources.each { |r| resources(r, options) } - return self - end - - if path_names = options.delete(:path_names) - scope(:resources_path_names => path_names) do - resources(resources, options) - end + if verify_common_behavior_for(:resources, resources, options, &block) return self end resource = Resource.new(resources.pop, options) - if @scope[:scope_level] == :resources - nested do - resources(resource.name, options, &block) - end - return self - end - scope(:path => resource.name.to_s, :controller => resource.controller) do with_scope_level(:resources, resource) do yield if block_given? @@ -595,6 +563,29 @@ module ActionDispatch path_names[name.to_sym] || name.to_s end + def verify_common_behavior_for(method, resources, options, &block) + if resources.length > 1 + resources.each { |r| send(method, r, options, &block) } + return true + end + + if path_names = options.delete(:path_names) + scope(:resources_path_names => path_names) do + send(method, resources.pop, options, &block) + end + return true + end + + if @scope[:scope_level] == :resources + nested do + send(method, resources.pop, options, &block) + end + return true + end + + false + end + def with_exclusive_name_prefix(prefix) begin old_name_prefix = @scope[:name_prefix] -- cgit v1.2.3