{"id":13484372,"url":"https://github.com/amerine/acts_as_tree","last_synced_at":"2025-03-27T16:30:46.924Z","repository":{"id":417662,"uuid":"1319339","full_name":"amerine/acts_as_tree","owner":"amerine","description":"ActsAsTree -- Extends ActiveRecord to add simple support for organizing items into parent–children relationships.","archived":false,"fork":true,"pushed_at":"2022-04-23T09:53:04.000Z","size":162,"stargazers_count":587,"open_issues_count":13,"forks_count":87,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-10-30T02:30:57.393Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"rails/acts_as_tree","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amerine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-02-02T05:22:51.000Z","updated_at":"2024-09-21T10:01:43.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/amerine/acts_as_tree","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerine%2Facts_as_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerine%2Facts_as_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerine%2Facts_as_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amerine%2Facts_as_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amerine","download_url":"https://codeload.github.com/amerine/acts_as_tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245882241,"owners_count":20687857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:23.196Z","updated_at":"2025-03-27T16:30:45.275Z","avatar_url":"https://github.com/amerine.png","language":"Ruby","funding_links":[],"categories":["ORM/ODM Extensions","Ruby"],"sub_categories":[],"readme":"# ActsAsTree\n[![CI](https://github.com/amerine/acts_as_tree/actions/workflows/ci.yml/badge.svg)](https://github.com/amerine/acts_as_tree/actions/workflows/ci.yml)\n[![Gem Version](https://badge.fury.io/rb/acts_as_tree.svg)](http://badge.fury.io/rb/acts\\_as\\_tree)\n\nActsAsTree extends ActiveRecord to add simple support for organizing items into parent–children relationships. By default, ActsAsTree expects a foreign key column called `parent_id`.\n\n## Example\n\n```ruby\nclass Category \u003c ActiveRecord::Base\n  acts_as_tree order: \"name\"\nend\n\nroot      = Category.create(\"name\" =\u003e \"root\")\nchild1    = root.children.create(\"name\" =\u003e \"child1\")\nsubchild1 = child1.children.create(\"name\" =\u003e \"subchild1\")\n\nroot.parent   # =\u003e nil\nchild1.parent # =\u003e root\nroot.children # =\u003e [child1]\nroot.children.first.children.first # =\u003e subchild1\n```\n\nWe also have a convenient `TreeView` module you can mixin if you want a little visual representation of the tree structure. Example:\n\n```ruby\nclass Category \u003c ActiveRecord::Base\n  extend ActsAsTree::TreeView\n\n  acts_as_tree order: 'name'\nend\n\n\u003e Category.tree_view(:name)\nroot\n |_ child1\n |    |_ subchild1\n |    |_ subchild2\n |_ child2\n      |_ subchild3\n      |_ subchild4\n=\u003e nil\n```\n\nAnd there's a `TreeWalker` module (traversing the tree using depth-first search (default) or breadth-first search) as well. Example given the Model `Page` as\n\n```ruby\nclass Page \u003c ActiveRecord::Base\n  extend ActsAsTree::TreeWalker\n\n  acts_as_tree order: 'rank'\nend\n```\n\nIn your view you could traverse the tree using\n\n```erb\n\u003c% Page.walk_tree do |page, level| %\u003e\n  \u003c%= link_to \"#{'-'*level}#{page.name}\", page_path(page) %\u003e\u003cbr /\u003e\n\u003c% end %\u003e\n```\n\nYou also could use walk\\_tree as an instance method such as:\n\n```erb\n\u003c% Page.first.walk_tree do |page, level| %\u003e\n  \u003c%= link_to \"#{'-'*level}#{page.name}\", page_path(page) %\u003e\u003cbr /\u003e\n\u003c% end %\u003e\n```\n\n## Compatibility\n\nWe no longer support Ruby 1.8 or versions of Rails/ActiveRecord older than 3.0. If you're using a version of ActiveRecord older than 3.0 please use 0.1.1.\n\nMoving forward we will do our best to support the latest versions of ActiveRecord and Ruby.\n\n## Change Log\n\nThe Change Log has moved to the [releases](https://github.com/amerine/acts_as_tree/releases) page.\n\n## Note on Patches/Pull Requests\n\n1. Fork the project.\n2. Make your feature addition or bug fix.\n3. Add tests for it. This is important so we don't break it in a future version\n   unintentionally.\n4. Commit, do not mess with rakefile, version, or history. (if you want to have\n   your own version, that is fine but bump version in a commit by itself so we can\n   ignore when we pull)\n5. Send us a pull request. Bonus points for topic branches.\n6. All contributors to this project, after their first accepted patch, are given push\n   access to the repository and are welcome as full contributors to ActsAsTree. All\n   we ask is that all changes go through CI and a Pull Request before merging.\n\n## Releasing new versions\n\n1. We follow Semver. So if you're shipping interface breaking changes then bump\n   the major version. We don't care if we ship version 1101.1.1, as long as\n   people know that 1101.1.1 has breaking differences from 1100.0. If you're\n   adding new features, but not changing existing functionality bump the minor\n   version, if you're shipping a bugfix, just bump the patch.\n2. Following the above rules, change the version found in lib/acts\\_as\\_tree/version.rb.\n3. Commit these changes in one \"release-prep\" commit (on the master branch).\n4. Push that commit up to the repo.\n5. Run `rake release`\n   This will create and push a tag to GitHub, then generate a gem and push it to\n   Rubygems.\n6. Create a new release from the tag on GitHub, by choosing \"Draft a new release\" button\n   on the [releases](https://github.com/amerine/acts_as_tree/releases) tab and include\n   the relevant changes in the description.\n7. Profit.\n\n## License (MIT)\n\nCopyright (c) 2007 David Heinemeier Hansson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the 'Software'), to deal in the\nSoftware without restriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell copies of the\nSoftware, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\nAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famerine%2Facts_as_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famerine%2Facts_as_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famerine%2Facts_as_tree/lists"}