Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Rails plugin which extends ActiveRecord to allow self-referential models (eg. acts_as_tree) to maintain a textual path representing itself and its ancestors.
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
rails
tasks
test
.gitignore
MIT-LICENSE
README.textile
Rakefile
VERSION
init.rb
install.rb
path_finder.gemspec
uninstall.rb

README.textile

PathFinder

A Rails plugin which extends ActiveRecord using the decorator pattern to allow self-referential models (eg. acts_as_tree) to maintain a textual path representing itself and its ancestors.

Install

gem install path_finder

Example

In association with a catch-all route you can find a record using the URL:

Hierarchy → Generated Path

  1. Categories → /categories
    1. Books → /categories/books
      1. Hardback → /categories/books/hardback
      2. Paperback → /categories/books/paperback
    2. Websites → /categories/websites

Example URL: http://mywebsite.co.uk/categories/books/hardback

category_controller.rb

def show
@category = Category.find_by_path(request.path)
end

category.rb

class Category < ActiveRecord::Base
acts_as_tree
path_finder :column => ‘path’, :uid => ‘to_param’, :deliminator => ‘/’

def to_param
permalink
end
end

Notes

The model must respond_to ‘children’

Copyright © 2010 Kris Leech, released under the MIT license

Something went wrong with that request. Please try again.