Wednesday, November 30, 2016

rails date_select examples

<%= date_select 'episode', 'published_at' %>

This generates date selection drop down that has 5 previous years, current year and the next 5 years.

<%= date_select 'episode', 'published_at', start_year: Date.current.year, end_year: 2000 %>

This starts from current year and goes back till year 2000.

<%= date_select 'episode', 'published_at', start_year: 1980 , end_year: Date.current.year - 10 %>

You can provide fixed start year and go back 10 years from current year as shown above.

<%= date_select 'episode', 'published_at', order: [:month, :day, :year], start_year: 1980 , end_year: Date.current.year - 10 %>

You can provide the order of month, day and year in the order option as shown above.




No comments:

Post a Comment