Skip to content

Commit

Permalink
Fix resources_path_names branch which was sending an array as entity. [
Browse files Browse the repository at this point in the history
…#3715 status:resolved]
  • Loading branch information
josevalim committed Jan 17, 2010
1 parent 58136e1 commit 44a10a2
Showing 1 changed file with 25 additions and 34 deletions.
59 changes: 25 additions & 34 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -418,28 +418,12 @@ def initialize(*args)
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?
Expand All @@ -459,28 +443,12 @@ def resource(*resources, &block)
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?
Expand Down Expand Up @@ -595,6 +563,29 @@ def action_path(name, path_names = nil)
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]
Expand Down

0 comments on commit 44a10a2

Please sign in to comment.