I am using Rails 3.1 . Here is the code I have which asks user to enter credit card expiration month and year.
<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.
Expiration dates appear on the front or back of a credit card in a two-digit month/year format. Credit cards expire at the end of the month written on the card. For example, a credit card's expiration date may read as 11/24, which means the card is active through the last day of November 2024.
The abbreviation MM / YY corresponds to the expiration date of the credit or debit card you are going to pay with. You will find it on the front of the card, below "expires end". The term "MM" refers to the two-digit representation of the month.
Card expiration dates generally come in a two-number format, with the first number representing the month and the second showing the year. For example, 09/23 would be September of 2023.
Some of the reasons you might see an "Invalid Card" error: The credit card has expired, reached its limit, or is not being authorized as a valid credit card. The credit card is not authorized for Internet transactions or has some other block in place.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With