我试图拥有< select>需要我的Rails表单.
这是我的代码(elipsis是使线更短):
<div class="field"> <p><%= f.label :category,"Category:" %></p> <%= f.select :category,['Analytics','Commerce',...,'Web'],:prompt => '-- Select One --',:required => true %> </div>
哪些输出
<div class="field"> <p><label for="startup_category">Category:</label></p> <select id="startup_category" name="startup[category]"> <option value="">-- Select One --</option> <option value="Analytics">Analytics</option> <option value="Commerce">Commerce</option> <option value="Content Management">Content Management</option> <option value="Gaming">Gaming</option> <option value="Green">Green</option> <option value="Media">Media</option> <option value="Social Media">Social Media</option> <option value="Technology - Software">Technology - Software</option> <option value="Technology - Hardware">Technology - Hardware</option> <option value="Web">Web</option></select> </div>
将{:required => true}而不是:required => true给出语法错误,并且{:prompt => ‘ – 选择一个 – ‘,:必需=> true}呈现页面,但在我的选择标签中没有required =“true”.
解决方法
试试这个….
f.select :category,{ :include_blank => '-- Select One --' },:required => true