Permalink
Browse files

Seperate scope level for nesting resources

  • Loading branch information...
1 parent 33658ea commit c4df6332a4d8292dd7d6bd6a1badc896a2323d11 @josh josh committed Dec 8, 2009
Showing with 16 additions and 8 deletions.
  1. +16 −8 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -291,10 +291,8 @@ def resource(*resources, &block)
resource = SingletonResource.new(resources.pop)
if @scope[:scope_level] == :resources
- with_scope_level(:member) do
- scope(parent_resource.id_segment, :name_prefix => parent_resource.member_name) do
- resource(resource.name, options, &block)
- end
+ nested do
+ resource(resource.name, options, &block)
end
return self
end
@@ -329,10 +327,8 @@ def resources(*resources, &block)
resource = Resource.new(resources.pop)
if @scope[:scope_level] == :resources
- with_scope_level(:member) do
- scope(parent_resource.id_segment, :name_prefix => parent_resource.member_name) do
- resources(resource.name, options, &block)
- end
+ nested do
+ resources(resource.name, options, &block)
end
return self
end
@@ -387,6 +383,18 @@ def member
end
end
+ def nested
+ unless @scope[:scope_level] == :resources
+ raise ArgumentError, "can't use nested outside resources scope"
+ end
+
+ with_scope_level(:nested) do
+ scope(parent_resource.id_segment, :name_prefix => parent_resource.member_name) do
+ yield
+ end
+ end
+ end
+
def match(*args)
options = args.extract_options!

0 comments on commit c4df633

Please sign in to comment.