Skip to content

Commit

Permalink
Make namespace_segments persist in a request, so it can be tweaked fo…
Browse files Browse the repository at this point in the history
…r non-standard controllers
  • Loading branch information
ianwhite committed Jan 29, 2010
1 parent 800ef8f commit 0f8f5f2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/ardes/resources_controller/request_path_introspection.rb
Expand Up @@ -19,9 +19,15 @@ def nesting_segments
@nesting_segments ||= segments_for_path_and_keys(nesting_request_path, param_keys)
end

# returns an array of segments correspopnding to the namespace of the controller.
# If your controller is at a non standard location wrt it's path, you can modify this array in a before filter
# to help resources_controller do the right thing
def namespace_segments
namespace = controller_path.sub(%r(#{controller_name}$), '')
request_path =~ %r(^/#{namespace}) ? namespace.split('/') : []
unless @namespace_segments
namespace = controller_path.sub(%r(#{controller_name}$), '')
@namespace_segments = (request_path =~ %r(^/#{namespace}) ? namespace.split('/') : [])
end
@namespace_segments
end

def param_keys
Expand Down

0 comments on commit 0f8f5f2

Please sign in to comment.