0

new.html.erb

 Price:  <%= f.collection_select :price_ids, Price.all, :id,:name,prompt: true %> JD

コントローラーで:

def dress_attributes
  dress_attributes = params.require(:dress).permit(:name,:email,:phone,:description,:image,:image2,[:price_ids: []})
end

show.html.erbで:

Price: <% @dress.prices.each do |s| %>
         <%= s.name %> 
       <% end %>`

そして、価格は表示されません。

を に変更すると何が問題にcollection_selectなりcollection_checked_boxesますか? 動作しますが、collection_select.

4

1 に答える 1

0

multiple: true以下に示すように、html_options として collection_select に渡すことができます。

new.html.erb

 Price:  <%= f.collection_select :price_id, Price.all, :id,:name, {prompt: true}, {multiple: true} %> JD

コントローラーで

def dress_attributes
  dress_attributes = params.require(:dress).permit(:name,:email,:phone,:description,:image,:image2,:price_id)
end

次に、コントローラーで、params[:dress][:price_id]選択した価格の配列である price_id にアクセスできます。

于 2015-06-07T21:44:31.667 に答える