0

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, admin is the parent of leader and leader is the parent of member.

In my create method for new User i did the following

@user = User.new root = @user.create("account_type" => "admin")

but i got an error undefined method create.. I am a bit confused as to how can i initialize or implement the acts_as_tree gem from the controller

Any ideas will be appreciated

Thanks

Kingsley Simon
  • 2,090
  • 5
  • 38
  • 84

1 Answers1

0

Well you normally cannot create via the instance,but you can create via the association. So assuming you have the parent_id column set as a foreign key, you should be able to do something like this.

root = User.create(account_type: "admin")
leader = root.children.create(account_type: "leader")
member = leader.children.create(account_type: "member") 

Which will create a new user, called root with an account_type of admin, then create a child with account_type of leader, and then create a child of the leader with account_type member.

Doon
  • 19,719
  • 3
  • 40
  • 44