ruby-on-rails – Rails表单选择必需

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails表单选择必需前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图拥有< select>需要我的Rails表单.

这是我的代码(elipsis是使线更短):@H_502_3@

<div class="field">
  <p><%= f.label :category,"Category:" %></p>
  <%= f.select :category,['Analytics','Commerce',...,'Web'],:prompt => '-- Select One --',:required => true %>
</div>

哪些输出@H_502_3@

<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”.@H_502_3@

如何在我的标签中获得required =“true”?@H_502_3@

解决方法

试试这个….
f.select :category,{ :include_blank => '-- Select One --' },:required => true
原文链接:https://www.f2er.com/ruby/266010.html

猜你在找的Ruby相关文章