0.0
No commit activity in last 3 years
No release in over 3 years
Textual path for self-referential models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

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