Skip to content

Commit

Permalink
Ensure that the current segment (removed from request_path to give en…
Browse files Browse the repository at this point in the history
…closing path) is singelton aware
  • Loading branch information
ianwhite committed Oct 8, 2009
1 parent 5d21f7f commit d2cd1e9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/ardes/resources_controller/request_path_introspection.rb
Expand Up @@ -11,7 +11,7 @@ def request_path
end

def nesting_request_path
@nesting_request_path ||= remove_namespace(request_path.sub(%r(/#{current_segment}(?!.+/#{current_segment}).*$), ''))
@nesting_request_path ||= remove_namespace(remove_current_segment(request_path))
end

# returns an array of hashes like {:segment => 'forum', :singleton => false}
Expand All @@ -29,6 +29,14 @@ def param_keys
end

private
def remove_current_segment(path, singleton = false)
if respond_to?(:resource_specification) && resource_specification.singleton?
path.sub(%r(/#{current_segment}(?!.*/#{current_segment}).*$), '')
else
path.sub(%r(/#{current_segment}(?!.+/#{current_segment}).*$), '')
end
end

def current_segment
respond_to?(:resource_specification) ? resource_specification.segment : controller_name
end
Expand Down

0 comments on commit d2cd1e9

Please sign in to comment.