Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:26:53+00:00 2026-05-27T03:26:53+00:00

I need to one of my project use a tree structure. I found this

  • 0

I need to one of my project use a tree structure. I found this link and I tried it to use. My table structure looks this:

id    
user_id
parent_id
lft
rgt

When I try to create a root, so I will do this:

save_tree = TreeStruct.create!(:user_id => @user.id)

And then I try to add the childern:

  save_tree = TreeStruct.create!(:user_id => @user.id)
  save_tree.move_to_child_of(params[:parent])

But in this moment I am stil over and over again getting the error Couldn’t find TreeStruct with id=12. The content of my DB table with the tree structure is here:

+----+---------+-----------+------+------+---------------------+---------------------+
| id | user_id | parent_id | lft  | rgt  | created_at          | updated_at          |
+----+---------+-----------+------+------+---------------------+---------------------+
|  1 |      12 |      NULL |    1 |    2 | 2011-11-30 04:09:41 | 2011-11-30 04:09:41 |
+----+---------+-----------+------+------+---------------------+---------------------+

Could anyone help me, please, what I am still doing wrong? I can’t find on the right way to use this gem… Why is there needed ID with the value 12? I though this is not needed…

Million times thanks for every help! I am struggling with this problem already second day and still can’t find the main problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:26:54+00:00Added an answer on May 27, 2026 at 3:26 am

    I’d recomment to use the “ancestry” gem — it’s excellent at supporting tree structures. It stores the list of ancestors in a comma-separated string, which makes look-ups very efficient.

    http://railscasts.com/episodes/262-trees-with-ancestry

    https://github.com/stefankroes/ancestry

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use one of my VB.NET projects in a C++ project. The
I need to have one lib-project (myLib), and several apps projects that should use
i need to have one project on asp.net mvc 1 but i want to
I am working on one project where there is a functionality need to implement
I need to build a solution, but exclude one project. How should I do
Actually in one of my project i need to read images from remote server
The Zipper data structure is great when one wants to traverse a tree and
In one of my projects I need to build an ASP.NET page and some
I need one of my .exe to always run as administrator without UAC prompt.
I am working on one joomla(2.5.1) site and i need one module for one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.