选择字段:
<%= f.select :study_material_type, StudyMaterial::TYPES.map{|v| [v,v]}, selected: f.object.try(:study_material_type) , required: true,include_blank: "Please select a Study Material"%>
我想验证:study_material_type
选择字段的存在。我怎么能这样做?
答案 0 :(得分:-1)
选择包含5个以上选项,required
验证为html_option
即
select(object, method, choices = nil, options = {}, html_options = {}, &block)
将html参数放在{ }
中作为html_options
。这应该适合你。
<%= f.select :study_material_type, StudyMaterial::TYPES.map{|v| [v,v]}, {include_blank: "Please select a Study Material"}, {required: true } %>
Here是一个很好的材料,让您更好地理解。