An open API service indexing awesome lists of open source software.

https://github.com/krisleech/path-finder

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.
https://github.com/krisleech/path-finder

Last synced: about 1 year ago
JSON representation

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.

Awesome Lists containing this project

README

          

h2. 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.

h3. Install

gem install path_finder

h3. Example

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

Hierarchy -> Generated Path

# Categories -> /categories
## Books -> /categories/books
### Hardback -> /categories/books/hardback
### Paperback -> /categories/books/paperback
## 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

h3. Notes

The model must respond_to 'children'

Copyright (c) 2010 Kris Leech, released under the MIT license