私はモンゴイドとレールにまったく慣れていません。そのため、ツリー構造を機能させるにはいくつかの問題があります。
構築する 3 つの「ソリューション」を見つけました
mongoid-tree (これが最も実際のものです) https://github.com/benedikt/mongoid-tree
そしてモンゴイドが提供するソリューション recurively_embeds_more
mongoid_acts_as_tree https://github.com/saks/mongoid_acts_as_tree
私の目標は、さまざまなモデルで参照/埋め込みできる音楽スタイルのツリーを作成することです。
- -家
- ---テックハウス
- ---ミニマルハウス
- -フォーク
- ---アフリカ
- ---アジア人
- -金属
- - -ヘヴィメタル
- - -デスメタル
- .....
私のモデルは次のようになります。
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
とビュー
<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>
私は何時間も実例を探しましたが、成功しませんでした。
理解を深めるために、誰かが私にいくつかのコード行を提供してくれるかもしれません
どんな助けでも私の一日を作ります
よろしくお願いします