http://simple-form.plataformatec.com.br/#usage/collectionsに simple_form 2.0 の grouped_select 機能に関するドキュメントが少しあるようです。ドキュメントには次の行があります。
f.input :country_id, :collection => @continents, :as => :grouped_select, :group_method => :countries
しかし、それはそれを機能させるのに十分なコンテキストを私に与えていないようです. これが私が持っているものです。
お問い合わせ、広告、挿入の 3 つのモデルがあります。
Ads has_many Insertions, and Insertions belongs_to Ads Inquiries belongs_to Insertion, and Insertions has_many Inquiries
このドロップダウンは照会ビュー用です。simple_form を使用する= f.input :insertion, :collection => @ads
と、少なくともドロップダウンに広告タイトルのリストを出力できます。ad.title を optgroup として機能させたいと思います。次に、広告の挿入を選択可能なコンテンツとして提供したいと思います...次のようなものです:
<select>
<optgroup label="Ad.Title">
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
</optgroup>
<optgroup label="Ad.Title">
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
<option value="Ad.Insertion.id">Ad.Insertion.Title</option>
</optgroup>
</select>
この simple_form 機能を機能させるためのアドバイスはありますか? 本当に感謝します!
このプロパティを実行する方法について洞察があれば、アプリについて他に何か言えることがあれば教えてください。
前もって感謝します!
更新:次を使用して部分的に機能するものを取得できました:
= f.input(:insertion_id, :collection => Ad.order(:name), :as => :grouped_select, :group_method => :insertions)
これに関する問題は、私が知る限り、どの列を表示テキストとして使用するかを指定する方法がないことです。どんな意見でも歓迎します。