Html 集合选择框和集合选中框之间的差异

Html 集合选择框和集合选中框之间的差异,html,ruby-on-rails,ruby,embedded-ruby,Html,Ruby On Rails,Ruby,Embedded Ruby,new.html.erb Price: <%= f.collection_select :price_ids, Price.all, :id,:name,prompt: true %> JD 在show.html.erb中: def dress_attributes dress_attributes = params.require(:dress).permit(:name,:email,:phone,:description,:image,:image2,[:price_

new.html.erb

 Price:  <%= f.collection_select :price_ids, Price.all, :id,:name,prompt: true %> JD
在show.html.erb中:

def dress_attributes
  dress_attributes = params.require(:dress).permit(:name,:email,:phone,:description,:image,:image2,[:price_ids: []})
end
Price: <% @dress.prices.each do |s| %>
         <%= s.name %> 
       <% end %>`
价格:
`
而且价格没有显示出来


当我将
collection\u select
更改为
collection\u checked\u复选框时有什么问题?它可以工作,但我希望
集合\u选择

您可以将
multiple:true
作为html选项传递给集合\u选择,如下所示

new.html.erb

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

然后,在控制器中,您可以访问price\u id作为
参数[:dress][:price\u id]
,这将是一个选定价格的数组。

[:price\u id:[]}
,您真的这样写吗?
def dress_attributes
  dress_attributes = params.require(:dress).permit(:name,:email,:phone,:description,:image,:image2,:price_id)
end