I am quite new to mongoid and rails. So I have some troubles to get an tree structure working:
I found three "solutions" to build
mongoid-tree (which is the most actual one) https://github.com/benedikt/mongoid-tree
and the mongoid provided solution recursively_embeds_more
mongoid_acts_as_tree https://github.com/saks/mongoid_acts_as_tree
my goal is to make a tree for musicstyles which can be referenced/embedded in different models.
- -House
- ---Tech House
- ---Minimal House
- -Folk
- ---African
- ---Asian
- -Metal
- ---Heavy Metal
- ---Death Metal
- .....
My Model looks now like this:
class Musicstyle
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Tree # mongoid-tree Version
recursively_embeds_many # mongoids version itself
field :musicstyle, type: String
field :description, type: String
field :parent
end
and the view
<div class="field">
<%= f.label :parent %>
<%= f.select :parent,
Musicstyle.all.map { |m| [m.musicstyle, m._id] },
{:include_blank => "Select a parent (if needed)"} %>
</div>
I searched now for hours for an working example, without success.
Maybe someone can offer me some lines of code for a better understanding
any help will make my day
many, many thanks in advance