github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

collectiveidea / awesome_nested_set

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 504
    • 61
  • Source
  • Commits
  • Network (61)
  • Issues (6)
  • Downloads (7)
  • Wiki (4)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (7)
    • v1.4.3
    • v1.4.2
    • v1.4.1
    • v1.4.0
    • v1.3.0
    • v1.2.0
    • v0.0.0
Sending Request…
Click here to lend your support to: awesome_nested_set and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

An awesome replacement for acts_as_nested_set and better_nested_set. — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added note in the README about rebuild! which is awesome for converting 
from other trees. Comment
danielmorrison (author)
Tue Dec 22 06:09:46 -0800 2009
commit  b9aba888f5f28e7ce47af4a36c2ae1df17640b38
tree    56855d5ee50d6014cdf6561ec81293c3eb00ef50
parent  2972647cd57b500deea58c80ef5cb0e39f6cbc65
awesome_nested_set /
name age
history
message
file .autotest Thu Aug 21 20:30:15 -0700 2008 changed autotest mapping [brandon]
file .gitignore Mon Oct 13 14:54:39 -0700 2008 First pass at gemification [ggoodale]
file MIT-LICENSE Thu Oct 18 06:46:41 -0700 2007 new implementation of nested set based off of b... [brandon]
file README.rdoc Tue Dec 22 06:10:01 -0800 2009 Added note in the README about rebuild! which i... [danielmorrison]
file Rakefile Fri Nov 27 09:13:29 -0800 2009 Require rubygems in the rakefile [brandon]
file VERSION Wed Oct 07 16:30:42 -0700 2009 Version bump to 1.4.3 [brandon]
file awesome_nested_set.gemspec Wed Oct 07 16:32:46 -0700 2009 Regenerated gemspec for version 1.4.3 [brandon]
file init.rb Mon Oct 13 15:15:12 -0700 2008 Fixed init.rb hook to play nice with Rails 2.1'... [ggoodale]
directory lib/ Fri Sep 25 16:36:29 -0700 2009 don't de-namespace class name in associations [Kevin Bullock]
directory rails/ Tue Aug 11 08:46:15 -0700 2009 Remove support for versions of rails < 2.1 [brandon]
directory test/ Fri Nov 27 08:20:47 -0800 2009 Test case to ensure awesome_nested_set does not... [brandon]
README.rdoc

AwesomeNestedSet

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. It supports Rails 2.1 and later.

What makes this so awesome?

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.

Installation

Install as a plugin:

  script/plugin install git://github.com/collectiveidea/awesome_nested_set.git

Usage

To make use of awesome_nested_set, your model needs to have 3 fields: lft, rgt, and parent_id:

  class CreateCategories < ActiveRecord::Migration
    def self.up
      create_table :categories do |t|
        t.string :name
        t.integer :parent_id
        t.integer :lft
        t.integer :rgt
      end
    end

    def self.down
      drop_table :categories
    end
  end

Enable the nested set functionality by declaring acts_as_nested_set on your model

  class Category < ActiveRecord::Base
    acts_as_nested_set
  end

Run `rake rdoc` to generate the API docs and see CollectiveIdea::Acts::NestedSet::SingletonMethods for more info.

Conversion from other trees

Coming from acts_as_tree or another system where you only have a parent_id? No problem. Simply add the lft & rgt fields as above, and then run

  Category.rebuild!

Your tree be converted to a valid nested set. Awesome!

View Helper

The view helper is called #nested_set_options.

Example usage:

  <%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>

  <%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>

See CollectiveIdea::Acts::NestedSet::Helper for more information about the helpers.

References

You can learn more about nested sets at:

  http://www.dbmsmag.com/9603d06.html
  http://threebit.net/tutorials/nestedset/tutorial1.html
  http://api.rubyonrails.com/classes/ActiveRecord/Acts/NestedSet/ClassMethods.html
  http://opensource.symetrie.com/trac/better_nested_set/

How to contribute

If you find what you might think is a bug:

  1. Check the GitHub issue tracker to see if anyone else has had the same issue. github.com/collectiveidea/awesome_nested_set/issues/
  2. If you don’t see anything, create an issue with information on how to reproduce it.

If you want to contribute an enhancement or a fix:

  1. Fork the project on github. github.com/collectiveidea/awesome_nested_set/
  2. Make your changes with tests.
  3. Commit the changes without making changes to the Rakefile, VERSION, or any other files that aren’t related to your enhancement or fix
  4. Send a pull request.

Copyright ©2008 Collective Idea, released under the MIT license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server