I am using Rails 3.1 . Here is the code I have which asks user to enter credit card expiration month and year.
我正在使用Rails 3.1。这是我的代码,要求用户输入信用卡到期月份和年份。
<div class="field">
<%= f.label :expires_on, 'Expiration date' %>
<br />
<%= select_month nil, {add_month_numbers: true}, {name: 'creditcard[month]', id: "card_month"} %>
<%= select_year nil, {start_year: Date.today.year, end_year: Date.today.year+15}, {name: 'creditcard[year]', id: "card_year"} %>
</div>
Above code works. However the issue is that if there was a validation error then the selected expiration and month are reset.
以上代码有效。但问题是,如果存在验证错误,则重置所选的到期日和月份。
I tried f.select_month
but that is not supported.
我尝试了f.select_month,但不支持。
1 个解决方案
#1
14
Try something like this:
尝试这样的事情:
<p>
<%= f.label :expires_on, 'Expiration date' %><br />
<%= f.date_select :expires_on, :discard_day => true, :start_year => Date.today.year, :end_year => (Date.today.year+10), :use_month_numbers => true %>
</p>
#1
14
Try something like this:
尝试这样的事情:
<p>
<%= f.label :expires_on, 'Expiration date' %><br />
<%= f.date_select :expires_on, :discard_day => true, :start_year => Date.today.year, :end_year => (Date.today.year+10), :use_month_numbers => true %>
</p>