ruby-on-railshierarchyancestry

Rails: Hierarchical select for a model with ancestry


I need to display a hierarchical structured select menu of categories.

Im using Ancestry on my categories model so I can create the categories and sub-categories.

In my schema I have another model "oferts" it has a many-to-many relationship with categories so while creating the oferts I want to select the category of the ofert. would be great to if after select the parent then load the childs in another select.

Anyone know how to do this? I took a try but couldn't figure out a simple way. Here is the visual example:

 Category 1
    Sub-Cat 1.1
    Sub-Cat 1.2
  Category 2
    Sub-Cat 2.1
    Sub-Cat 2.2
  Category 3
  Category 4

Thanks for you help.


Solution

  • Take a look to this nice article talking about this functionality we could implement it in many of our forms, very nice, the solution was to use a little bit of ajax

    Hope this helps you!