ruby - How to add addional 0 to select_month option in rails -
heres code
<%= select_month nil, {use_two_digit_numbers: true}, {:name => 'expmonth', class: "form-control" } %>
and results
<select class="form-control" id="date_month" name="expmonth"> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option> <option value="4">04</option> <option value="5">05</option> <option value="6">06</option> <option value="7">07</option> <option value="8">08</option> <option value="9">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select>
if can see value of options has no "0" want add 0 01, 02 , except 10 12 double digit. see example below
<select class="form-control" id="date_month" name="expmonth"> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select>
i'd you're better off using like
select_tag 'date_month', options_for_select((1..12).collect{ |i| "%02d" % })
Comments
Post a Comment