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.
- Host: GitHub
- URL: https://github.com/krisleech/path-finder
- Owner: krisleech
- License: mit
- Created: 2010-02-09T13:35:58.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2010-02-11T12:46:25.000Z (over 16 years ago)
- Last Synced: 2025-03-17T04:44:46.423Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE
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