2
votes

I'm using simple-form, but I'm having a hard time to show the date_of_birth correctly. This is probably because of a combination of limited documentation on simple-form and more so the fact that I'm a rooky.

Anyways, I'm trying to create a collection of the years people can choose from for their birthdate.

date_of_birth is an attribute of the user in the DATE form, which requires input of a year, month and day. Now I tried to change the collection for the years as below, but this removes the input fields for day and month:

= simple_form_for(@user, :html => { :class => 'form-horizontal' }) do |f|
  ...
  = f.input :date_of_birth, :collection => 1910..2010

I'm using Simple-form on Ruby on Rails with HAML. So question is: What is the correct way to just define the collection for the years, keeping the defaults for the input of day and month?

1

1 Answers

3
votes

the following code should do the trick:

f.input :date_of_birth, :as => :date,
        :start_year => 1910, :end_year => 2010,
        :order => [:day, :month, :year]

(The previous code is untested and could cause the end of the world as Mayan predicted)

You can find the documentation for SimpeForm here (try to look for date_of_birth ;))