Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

An awesome replacement for acts_as_nested_set and better_nested_set.

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time



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.


Install as a plugin:

script/plugin install git://


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

  def self.down
    drop_table :categories

Enable the nested set functionality by declaring acts_as_nested_set on your model

class Category < ActiveRecord::Base

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

View Helper

The view helper is called #nested_set_options.

Example usage:

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

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

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


You can learn more about nested sets at:

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.

  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.

  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

Something went wrong with that request. Please try again.