Rails has_many :through with collection_select form helper

后端 未结 2 685
悲&欢浪女
悲&欢浪女 2021-01-25 12:35

I\'m having issues with creating a form that will save my has_many :through associations. I\'ve successfully saved by posting json, but the forms just won\'t work for me yet.

2条回答
  •  一个人的身影
    2021-01-25 13:33

    For anyone fighting the same kind of issue, I finally managed to get this to work with the following collection_select:

          <%= f.collection_select(:feature_ids, Feature.all, :id, :name,
                                  {include_blank: false, :include_hidden => false, :selected => @property.features.map(&:id)},
                                  {:multiple => true}) %>
    

提交回复
热议问题