Questions tagged [acts-as-tree]

ActsAsTree extends ActiveRecord to add simple support for organizing items into parent–children relationships. By default, ActsAsTree expects a foreign key column called parent_id.

52 questions
1
vote
3 answers

Acts_as_tree - one-to-Many: Show Records associated with children on parent page

I have a relatively simple one-to-many relationship and use acts_as_tree to get it organized in the view. It kinda looks like this: Root |_Product 1 |_Product 2 |_Category 1.1 |_Product 3 |_Product 4 |_Category…
val_to_many
  • 377
  • 5
  • 20
0
votes
1 answer

Acts As Tree: assigning parent to a child with letting parent know about it?

When I manually assign a parent to a child like this: parent = create :rule # I'm using FactoryBot to create test data child = create :rule, parent: parent Then the parent doesn't know about it: parent.children # => [] How can I make sure that the…
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152
0
votes
1 answer

Can a nested set have duplicate child objects or multiple parent_id/root/nodes?

Can a nested set have duplicate child objects or multiple parent_id/root/nodes? For instance, I want to create an application that can manage parts and equipment. However, a specific equipment can have the same parts from other equipment as…
chourobin
  • 4,004
  • 4
  • 35
  • 48
0
votes
1 answer

Rails - Acts as nested - Enforcing a Max Level

I'm currently using the gem 'nested_set' for comment threading. What I want to do is prevent the comment level from going more than 2 levels deep. What I tired doing was something like this: class Comment < ActiveRecord::Base .... …
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
0
votes
1 answer

Rspec with acts_as_tree: Helper does not see children

Trying to write a test for a helper method that uses acts_as_tree. Helper method uses a count for children: if category.children.size > 0 In my test, I'm creating a parent and child: parent = Factory.create(:category) child =…
jmccartie
  • 4,956
  • 8
  • 50
  • 71
0
votes
1 answer

Undefined method `acts_as_tree'

I am upgrading a project from rails 2 to 4 but cannot find what is the equivalent gem for "acts_as_tree" for rails 4. I saw threads saying "acts_as_tree" is already deprecated, so am looking for another way to use this method in Rails 4. Thank you!
skyranch
  • 55
  • 5
0
votes
1 answer

problem when installing rails plugins

I'm trying to install acts_as_tree plugin, i got no error from the command line but i still get : undefined local variable or methodacts_as_tree' for #` the vendor/acts_as_tree is empty and when i try install again i get : already installed:…
Gady
  • 1,514
  • 2
  • 16
  • 32
0
votes
1 answer

Id (autoincrementing integer) vs string employee ID as primary key - rails application

I'm writing my first rails app & want to get into some good habits from the start. The table in question is to be to hold employee data, one of the fields being the manager's ID. To reflect the hierarchical structure, I'm thinking of using…
bill
  • 1
0
votes
2 answers

Delete Children rails 4

I have the class project , class Project < ActiveRecord::Base has_many :Users acts_as_tree end I want to delete all children, if I delete the parent, in this case meaning, if I delete the project(parent) must be deleted all users (children) and…
Arthur
  • 185
  • 1
  • 1
  • 10
0
votes
1 answer

how to implement acts_as_tree on controller of a specific Model

So i want to implement the acts_as_tree gem for my User model. The column that i want to be in a tree form is my "account_type". account_type could be "admin, leader, member" root = admin root.children = leader leader.children = member Basically,…
Kingsley Simon
  • 2,090
  • 5
  • 38
  • 84
0
votes
0 answers

acts_as_tree not working with sinatra

I cant get acts_as_tree working with sinatra. I keep getting the following error. undefined method `acts_as_tree' for User I think its not supported for Sinatra. Any input is welcome. Just additional information. I am using Sinatra ActiveRecord
AMBasra
  • 969
  • 8
  • 24
0
votes
1 answer

How to combine two models in one RoR acts_as_tree treeview?

I have two simple models each with acts_as_tree, say Departments and Employees. My goal is to create a treeview combining both models in to one overall tree, like so: Department 1 SubDepartment 1.1 Employee A Employee B SubDepartment 1.2 …
Menno
  • 35
  • 2
  • 6
0
votes
1 answer

how to loop through an acts_as_tree or ancestry hierarchy

I'd like to take a structure like this where each header has a headers and items array: header header \item item item header header item header item item and make it into a list like this: …
timpone
  • 19,235
  • 36
  • 121
  • 211
0
votes
1 answer

Joining with named scopes in Ruby

I originally asked this question about acts_as_tree but it seems to be more general so I'm rephrasing it a bit here. I have a model "category" using acts_as_tree. I often find myself needing to join it with other models for various queries, but I…
shaimo
  • 376
  • 3
  • 17
0
votes
1 answer

Acts as Tree gem - Is there any way to make an element have two parents?

I am using the acts_as_tree gem in order to implement a category list in which a freelancer can select categories and subcategories. "Web design" is one of the subcategories, and it should have two parents: "Design" and "Web development". Is there…