如何在RoR中的number_field中设置最大和最小长度

时间:2016-10-20 11:53:31

标签: ruby-on-rails

<label class="control-label">count</label>
<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, :max=>"8",:min=>"8" } %>

4 个答案:

答案 0 :(得分:0)

如果您想要精确的8位数字,则min值为10000000max值为99999999

答案 1 :(得分:0)

是的,你几乎已经完成了。对此有一点改变:

<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, max: 8, min: 8 } %>

答案 2 :(得分:0)

<%= f.number_field :count, max: 10, min:4 %>

答案 3 :(得分:0)

试试这个:

<%= f.text_field :title, class: "form-control", title: "Enter title length 50 characters", placeholder: "Enter Title", :required => true,:maxlength => 50, pattern: ".{1,50}"  %>