Rails选择标记为必需的true

时间:2014-01-31 19:33:55

标签: ruby-on-rails ruby-on-rails-4 actionview

我有以下选择标记

<%= f.select :id, User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]}, {:required => true}, {:class => "multiselect", :multiple => true} %>

我尝试向其添加:required => true,视图呈现但:required => true不起作用!。

2 个答案:

答案 0 :(得分:1)

有点晚了,但对于任何人来说,查看https://stackoverflow.com/a/42373448/5298879,应该明确地作为哈希,所以ruby解释器不会混淆:

select(object, method, choices = nil, options = {}, html_options = {}, &block)

对于这种特殊情况:

<%= f.select :id,
             User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]},
             {:prompt => 'Select something'},
             {:required => true, :class => "multiselect", :multiple => true} %>

答案 1 :(得分:0)

试试这个:

<%= f.select :id, User.find(:all, :conditions => ["manager = ?", false]).collect {|u| [u.username, u.id]}, {:multiple => true}, :class => "multiselect", :required => true %>