0
私は複数選択にselect2を使用します。私の問題は、私はjsonデータから複数の値を選択でき、このデータを関連するモデル列に保存できることです。しかし、このモデルを更新したいときは、選択したデータは表示されません。選択した複数のデータが表示されません
私のJSONデータの一部:
{
- categories:[
- {
id:7,
name:"Eğitim Bilimleri Enstitüsü"
},
- {
id: 8,
name: "Eğitim Yönetim Teftişi ve Planlaması 1. Yarıyıl"
},
...
]
}
私は(それは、ちょうどクラスはActiveRecordから継承ではなく、それはJSONデータを返すいくつかの機能を持っている)Moodleのクラスを持っています。私はそれが正しいアプローチかどうか疑問に思います。私のフォームの内容で
:
<%= simple_form_for(@period) do |f| %>
...
<%= f.input :moodle_connect_ids, collection: Moodle.categories.map {|p| [ p['name'], p['id'] ] }, input_html: {multiple: true} %>
...
<% end %>
私は明示的に私のコントローラで配列することmoodle_connect_idsを設定します。
私の.jsファイルの内容でparams.require(:period).permit(..., :moodle_connect_ids => [])
:
$("#period_moodle_connect_ids").select2({
placeholder: "Moodle Dönem Bağlantılarını Seçiniz",
multiple: true,
allowClear: true
});
複数の値を選択してモデルを保存すると、列の値は次のようになります。
> Period.last
=> #<Period:0x007fcf53a4d830
id: 25,
...
moodle_connect_ids: "[\"\", \"85\", \"120\"]"
...
間違っていますか?あなたは何か提案していますか?