annotate vendor/plugins/awesome_nested_set/README.rdoc @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children
rev   line source
Chris@0 1 = AwesomeNestedSet
Chris@0 2
Chris@0 3 Awesome Nested Set is an implementation of the nested set pattern for ActiveRecord models. It is replacement for acts_as_nested_set and BetterNestedSet, but awesomer.
Chris@0 4
Chris@0 5 == What makes this so awesome?
Chris@0 6
Chris@0 7 This is a new implementation of nested set based off of BetterNestedSet that fixes some bugs, removes tons of duplication, adds a few useful methods, and adds STI support.
Chris@0 8
Chris@0 9 == Installation
Chris@0 10
Chris@0 11 If you are on Rails 2.1 or later:
Chris@0 12
Chris@0 13 script/plugin install git://github.com/collectiveidea/awesome_nested_set.git
Chris@0 14
Chris@0 15 == Usage
Chris@0 16
Chris@0 17 To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id:
Chris@0 18
Chris@0 19 class CreateCategories < ActiveRecord::Migration
Chris@0 20 def self.up
Chris@0 21 create_table :categories do |t|
Chris@0 22 t.string :name
Chris@0 23 t.integer :parent_id
Chris@0 24 t.integer :lft
Chris@0 25 t.integer :rgt
Chris@0 26 end
Chris@0 27 end
Chris@0 28
Chris@0 29 def self.down
Chris@0 30 drop_table :categories
Chris@0 31 end
Chris@0 32 end
Chris@0 33
Chris@0 34 Enable the nested set functionality by declaring acts_as_nested_set on your model
Chris@0 35
Chris@0 36 class Category < ActiveRecord::Base
Chris@0 37 acts_as_nested_set
Chris@0 38 end
Chris@0 39
Chris@0 40 Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.
Chris@0 41
Chris@0 42 == View Helper
Chris@0 43
Chris@0 44 The view helper is called #nested_set_options.
Chris@0 45
Chris@0 46 Example usage:
Chris@0 47
Chris@0 48 <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
Chris@0 49
Chris@0 50 <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
Chris@0 51
Chris@0 52 See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.
Chris@0 53
Chris@0 54 == References
Chris@0 55
Chris@0 56 You can learn more about nested sets at:
Chris@0 57
Chris@0 58 http://www.dbmsmag.com/9603d06.html
Chris@0 59 http://threebit.net/tutorials/nestedset/tutorial1.html
Chris@0 60 http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html
Chris@0 61 http://opensource.symetrie.com/trac/better_nested_set/
Chris@0 62
Chris@0 63
Chris@0 64 Copyright (c) 2008 Collective Idea, released under the MIT license