How to display the choice of month and year for a credit card

I am using Rails 3.1. Here is the code that I have that asks the user to enter the validity and credit card expiration dates.

<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> 

It works on the code. However, the problem is that if there was a validation error, then the selected expiration time and month are reset.

I tried f.select_month , but this is not supported.

+6
source share
1 answer

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> 
+14
source

Source: https://habr.com/ru/post/903109/


All Articles