简体   繁体   中英

rails form date_select for year with a range of years

I am trying to allow users to select month and year from dropdowns in a form. the month works great, but the year works but it displays 2015-2025 by default. I fond one that does work but I am not able to figure out how to add styling so it look likt eh other input fiels. here is what I have:

<%= f.date_select :month_started, {prompt: true, order: [:month]}, class:  'form-control' %>
<%= f.date_select :year_started, {prompt: true, order: [:year]}, class:  'form-control' %>

Here is the one that works but I cannot add a class to:

<%= f.select :year_started, Date.today.year-90 .. Date.today.year %>

Any help is greatly appreciate.

Ref this to add html options you have to do following.

<%= f.select :year_started, Date.today.year-90 .. Date.today.year, {}, {class:  'form-control'} %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM