[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7983":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":15,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":15,"lastSyncTime":27,"discoverSource":28},7983,"awesome_nested_set","collectiveidea\u002Fawesome_nested_set","collectiveidea","An awesome replacement for acts_as_nested_set and better_nested_set.","",null,"Ruby",2413,491,37,2,0,1,30.08,"MIT License",false,"main",true,[],"2026-06-12 02:01:47","# Awesome Nested Set\n\n[![CI](https:\u002F\u002Fgithub.com\u002Fcollectiveidea\u002Fawesome_nested_set\u002Factions\u002Fworkflows\u002Fci.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002Fcollectiveidea\u002Fawesome_nested_set\u002Factions\u002Fworkflows\u002Fci.yml) [![Code Climate](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fcollectiveidea\u002Fawesome_nested_set.svg)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002Fcollectiveidea\u002Fawesome_nested_set)\n\n\nAwesome Nested Set is an implementation of the nested set pattern for ActiveRecord models.\nIt is a replacement for acts_as_nested_set and BetterNestedSet, but more awesome.\n\nOlder versions: Version 3.2 supports Rails 6, 3.1 supports Rails 5 & 4. Version 2 supports Rails 3. \nGem versions prior to 2.0 support Rails 2.\n\n## What makes this so awesome?\n\nThis 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.\n\n\n## Installation\n\nAdd to your Gemfile:\n\n```ruby\ngem 'awesome_nested_set'\n```\n\n## Usage\n\nTo make use of `awesome_nested_set` your model needs to have 3 fields:\n`lft`, `rgt`, and `parent_id`. The names of these fields are configurable.\nYou can also have optional fields: `depth` and `children_count`. These fields are configurable.\nNote that the `children_count` column must have `null: false` and `default: 0` to\nfunction properly.\n\n```ruby\nclass CreateCategories \u003C ActiveRecord::Migration\n  def change\n    create_table :categories do |t|\n      t.string :name\n      t.integer :parent_id, null: true, index: true\n      t.integer :lft, null: false, index: true\n      t.integer :rgt, null: false, index: true\n\n      # optional fields\n      t.integer :depth, null: false, default: 0\n      t.integer :children_count, null: false, default: 0\n      t.timestamps\n    end\n  end\nend\n```\n\nEnable the nested set functionality by declaring `acts_as_nested_set` on your model\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set\nend\n```\n\nRun `rake rdoc` to generate the API docs and see [CollectiveIdea::Acts::NestedSet](lib\u002Fawesome_nested_set\u002Fawesome_nested_set.rb) for more information.\n\n## Options\n\nYou can pass various options to `acts_as_nested_set` macro. Configuration options are:\n\n* `parent_column`: specifies the column name to use for keeping the position integer (default: parent_id)\n* `primary_column`: specifies the column name to use as the inverse of the parent column (default: id)\n* `left_column`: column name for left boundary data (default: lft)\n* `right_column`: column name for right boundary data (default: rgt)\n* `depth_column`: column name for the depth data default (default: depth)\n* `scope`: restricts what is to be considered a list. Given a symbol, it'll attach `_id` (if it hasn't been already) and use that as the foreign key restriction. You can also pass an array to scope by multiple attributes. Example: `acts_as_nested_set :scope => [:notable_id, :notable_type]`\n* `dependent`: behavior for cascading destroy. If set to :destroy, all the child objects are destroyed alongside this object by calling their destroy method. If set to :delete_all (default), all the child objects are deleted without calling their destroy method. If set to :nullify, all child objects will become orphaned and become roots themselves.\n* `counter_cache`: adds a counter cache for the number of children. defaults to false. Example: `acts_as_nested_set :counter_cache => :children_count`\n* `order_column`: on which column to do sorting, by default it is the left_column_name. Example: `acts_as_nested_set :order_column => :position`\n* `touch`: If set to `true`, then the updated_at timestamp on the ancestors will be set to the current time whenever this object is saved or destroyed (default: false)\n\nSee [CollectiveIdea::Acts::NestedSet::Model::ClassMethods](\u002Flib\u002Fawesome_nested_set\u002Fmodel.rb#L26) for a list of class methods and [CollectiveIdea::Acts::NestedSet::Model](lib\u002Fawesome_nested_set\u002Fmodel.rb#L13) for a list of instance methods added to acts_as_nested_set models\n\n## Indexes\n\nIt is highly recommended that you add an index to the `rgt` column on your models. Every insertion requires finding the next `rgt` value to use and this can be slow for large tables without an index. It is probably best to index the other fields as well (`parent_id`, `lft`, `depth`).\n\n## Callbacks\n\nThere are three callbacks called when moving a node:\n`before_move`, `after_move` and `around_move`.\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set\n\n  after_move :rebuild_slug\n  around_move :da_fancy_things_around\n\n  private\n\n  def rebuild_slug\n    # do whatever\n  end\n\n  def da_fancy_things_around\n    # do something...\n    yield # actually moves\n    # do something else...\n  end\nend\n```\n\nBeside this there are also hooks to act on the newly added or removed children.\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set  :before_add     => :do_before_add_stuff,\n                      :after_add      => :do_after_add_stuff,\n                      :before_remove  => :do_before_remove_stuff,\n                      :after_remove   => :do_after_remove_stuff\n\n  private\n\n  def do_before_add_stuff(child_node)\n    # do whatever with the child\n  end\n\n  def do_after_add_stuff(child_node)\n    # do whatever with the child\n  end\n\n  def do_before_remove_stuff(child_node)\n    # do whatever with the child\n  end\n\n  def do_after_remove_stuff(child_node)\n    # do whatever with the child\n  end\nend\n```\n\n## Protecting attributes from mass assignment (for Rails \u003C 4)\n\nIt's generally best to \"whitelist\" the attributes that can be used in mass assignment:\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set\n  attr_accessible :name, :parent_id\nend\n```\n\nIf for some reason that is not possible, you will probably want to protect the `lft` and `rgt` attributes:\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set\n  attr_protected :lft, :rgt\nend\n```\n\n\n## Add to your existing project\n\nTo make use of `awesome_nested_set`, your model needs to have 3 fields:\n`lft`, `rgt`, and `parent_id`. The names of these fields are configurable.\nYou can also have optional fields, `depth` and `children_count`.\n\nCreate a migration to add fields:\n\n```ruby\nclass AddNestedToCategories \u003C ActiveRecord::Migration\n\n  def self.up\n    add_column :categories, :parent_id, :integer # Comment this line if your project already has this column\n    # Category.where(parent_id: 0).update_all(parent_id: nil) # Uncomment this line if your project already has :parent_id\n    add_column :categories, :lft,       :integer\n    add_column :categories, :rgt,       :integer\n\n    # optional fields\n    add_column :categories, :depth,          :integer\n    add_column :categories, :children_count, :integer\n\n    # This is necessary to update :lft and :rgt columns\n    Category.reset_column_information\n    Category.rebuild!\n  end\n\n  def self.down\n    remove_column :categories, :parent_id\n    remove_column :categories, :lft\n    remove_column :categories, :rgt\n\n    # optional fields\n    remove_column :categories, :depth\n    remove_column :categories, :children_count\n  end\n\nend\n```\n\nEnable the nested set functionality by declaring `acts_as_nested_set` on your model\n\n```ruby\nclass Category \u003C ActiveRecord::Base\n  acts_as_nested_set\nend\n```\n\nYour project is now ready to run with the `awesome_nested_set` gem!\n\n\n## Conversion from other trees\n\nComing 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:\n\n```ruby\nCategory.rebuild!\n```\n\nYour tree will be converted to a valid nested set. Awesome!\n\nNote: You can use `Category.rebuild!(false)` to skip model validations when performing the rebuild.\n\n## View Helper\n\nThe view helper is called #nested_set_options.\n\nExample usage:\n\n```erb\n\u003C%= f.select :parent_id, nested_set_options(Category, @category) {|i| \"#{'-' * i.level} #{i.name}\" } %>\n\n\u003C%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| \"#{'-' * i.level} #{i.name}\" } ) %>\n```\n\nSee [CollectiveIdea::Acts::NestedSet::Helper](lib\u002Fawesome_nested_set\u002Fhelper.rb) for more information about the helpers.\n\n## How to contribute\n\nPlease see the ['Contributing' document](CONTRIBUTING.md).\n\nCopyright © 2008–2015 [Collective Idea](http:\u002F\u002Fcollectiveidea.com), released under the MIT license.\n","Awesome Nested Set 是一个用于 ActiveRecord 模型的嵌套集合模式实现，旨在替代 acts_as_nested_set 和 BetterNestedSet。该项目通过修复一些已知问题、减少代码重复、增加实用方法以及支持单表继承（STI），提供了更加强大和灵活的解决方案。它特别适合需要高效管理树形结构数据的应用场景，如分类目录或组织架构等。支持 Rails 6 及以下版本，并可通过简单配置适应不同字段需求，易于集成到现有项目中。","2026-06-11 03:15:29","top_language"]