Rails 3: simple form start date

I use a simple form in my application to get the users birthday.

It is installed (and I want to keep it that way) to go back to the year 1900, but I was wondering if there is a way to start by default as 1950 (they can still go back to the old ones if they need to), so most users don’t you need to scroll them until you reach age.

<%= f.input :date_of_birth, :as => :date, :start_year => 1900, :end_year => Date.today.year - 12, :order => [ :day, :month, :year], :required => true %> 

Thanks!

+6
source share
3 answers

You can simply switch the value: start_year with the value: end_year to have

  <%= f.input :date_of_birth, :as => :date, :start_year => Date.today.year - 12, :end_year => 1900, :order => [ :day, :month, :year], :required => true %> 

Like: start_year and: end_year - this is exactly how you show the year ...

+5
source

I think datetime_select http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-datetime_select will be the one you need and set: default => {: year => 1950} what year you want it to show by default.

+1
source

You can use date_select http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html

and use the parameter: default

0
source

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


All Articles