Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 集合上的必填字段\u选择类型字段_Ruby On Rails_Forms_Ruby On Rails 4_Field_Form For - Fatal编程技术网

Ruby on rails 集合上的必填字段\u选择类型字段

Ruby on rails 集合上的必填字段\u选择类型字段,ruby-on-rails,forms,ruby-on-rails-4,field,form-for,Ruby On Rails,Forms,Ruby On Rails 4,Field,Form For,我有一个带有简单文本字段的表格,我要求填写该表格: <%= f.text_field :email, :required => true %> 如果没有:required=>true选项,代码工作正常。在这种情况下,如何强制用户进行选择?谢谢尝试更改此设置 <%= f.collection_select(:list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true}), :re

我有一个带有简单文本字段的表格,我要求填写该表格:

<%= f.text_field :email, :required => true %>
如果没有
:required=>true
选项,代码工作正常。在这种情况下,如何强制用户进行选择?谢谢

尝试更改此设置

<%= f.collection_select(:list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true}), :required => true %>
true%>
对此

<%= f.collection_select :list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true, required: true} %>

试试这个

<%= f.collection_select(:list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true, required: true}) %>
根据语法选项和html_选项是散列,因此需要将它们括在大括号中

参考-


注:
@来自控制器的MSR
:msr_cd-选项值`在此处输入代码`
:msr_cd-选项文本
我们可以通过上面的选择

你的答案几乎是复制的,如果你要复制,你应该相信别人回答你是对的,实际上我正要把这个标记为DUP谢谢你的帮助。这样,当你有更多问题时,社区中的其他人会帮助你。。。
<%= f.collection_select :list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true, required: true} %>
<%= f.collection_select(:list_ids, List.where(user_id: current_user), :id, :name, {}, {multiple: true, required: true}) %>
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
<%= form.collection_select :msr_cd, 
    @msrs, :msr_cd, :msr_cd,
      {multiple: false, required: true},
      data: { placeholder: "Select Measure" }, 
      class: "form-control col-sm-12 chosen-select"  
%>

Note:
    @msrs from the controller
    :msr_cd - option value`enter code here`
    :msr_cd - option text

We can pass the chosen select like above