Skip to content

Instantly share code, notes, and snippets.

@scharfie
Created February 6, 2009 16:37
Show Gist options
  • Save scharfie/59485 to your computer and use it in GitHub Desktop.
Save scharfie/59485 to your computer and use it in GitHub Desktop.
# helpers/path_helper.rb
module PathHelper
def path_as_array
path = (request.path_info || '').gsub(/^#{Bones.base}/, '')
path = path.split('/').map {|e| e.empty? ? nil : e}.compact
end
def current_path(depth=-1)
File.join('/', *[path_as_array[0..depth]])
end
def relative_path(path, depth=-1)
File.expand_path(File.join(current_path(depth), path))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment