I am having trouble getting the date_select tags in Rails to show a blank option. Here is my code:
<%= select_month(@foo, :include_blank => true) %>
But that code renders this HTML without a blank option.
<select id="month" name="month"><option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</op开发者_运维技巧tion>
</select>
Am I overlooking something?
Which version of rails are you using? I just tried this in the console (Rails 3.0.8) and it works:
ruby-1.9.2-p0 > include ActionView::Helpers::DateHelper
ruby-1.9.2-p0 > select_month( Time.now )
=> <select id="date_month" name="date[month]">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option selected="selected" value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
ruby-1.9.2-p0 > select_month( Time.now, :include_blank => true )
=> <select id="date_month" name="date[month]">
<option value=""></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option selected="selected" value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
精彩评论