Select tag with multiple values pre-selected - Values inserted manually in database

感情迁移 提交于 2019-12-05 08:28:55

options_from_collection_for_select has 4 parameters:

  • collection
  • id
  • column
  • selected

You can provide a single value, or a hash to denote selected values. Try this:

<%= select_tag "vacancy_ids[]", options_from_collection_for_select(Vacancy.all,"id","title",{:selected=>[1,2,3,4]})), :multiple => true, :id => "vacancy_ids", :class => "form-control" %>

I'm not sure where the values you are trying to select come from but pipe them into the selected hash.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!