annotate .svn/pristine/f7/f758fe470e3cc5243a9e779c6dc8af90264614da.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

Merge from branch "live"
author Chris Cannam
date Tue, 09 Sep 2014 09:34:53 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 = AwesomeNestedSet
Chris@909 2
Chris@909 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@909 4
Chris@909 5 == What makes this so awesome?
Chris@909 6
Chris@909 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@909 8
Chris@909 9 == Installation
Chris@909 10
Chris@909 11 If you are on Rails 2.1 or later:
Chris@909 12
Chris@909 13 script/plugin install git://github.com/collectiveidea/awesome_nested_set.git
Chris@909 14
Chris@909 15 == Usage
Chris@909 16
Chris@909 17 To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id:
Chris@909 18
Chris@909 19 class CreateCategories < ActiveRecord::Migration
Chris@909 20 def self.up
Chris@909 21 create_table :categories do |t|
Chris@909 22 t.string :name
Chris@909 23 t.integer :parent_id
Chris@909 24 t.integer :lft
Chris@909 25 t.integer :rgt
Chris@909 26 end
Chris@909 27 end
Chris@909 28
Chris@909 29 def self.down
Chris@909 30 drop_table :categories
Chris@909 31 end
Chris@909 32 end
Chris@909 33
Chris@909 34 Enable the nested set functionality by declaring acts_as_nested_set on your model
Chris@909 35
Chris@909 36 class Category < ActiveRecord::Base
Chris@909 37 acts_as_nested_set
Chris@909 38 end
Chris@909 39
Chris@909 40 Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.
Chris@909 41
Chris@909 42 == View Helper
Chris@909 43
Chris@909 44 The view helper is called #nested_set_options.
Chris@909 45
Chris@909 46 Example usage:
Chris@909 47
Chris@909 48 <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
Chris@909 49
Chris@909 50 <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
Chris@909 51
Chris@909 52 See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.
Chris@909 53
Chris@909 54 == References
Chris@909 55
Chris@909 56 You can learn more about nested sets at:
Chris@909 57
Chris@909 58 http://www.dbmsmag.com/9603d06.html
Chris@909 59 http://threebit.net/tutorials/nestedset/tutorial1.html
Chris@909 60 http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html
Chris@909 61 http://opensource.symetrie.com/trac/better_nested_set/
Chris@909 62
Chris@909 63
Chris@909 64 Copyright (c) 2008 Collective Idea, released under the MIT license