Search code examples
ruby-on-rails-3formsdateselecthelper

How can I set just the year and month for date_select for HAML and Rails 3?


I tried to set up the date_select in my HAML template for displaying just a year and month:

= date_select(:birthday, :order => [:day, :month, :year],:start_year => 1940)

I would expect this piece of code to display the select box sorted as: day, month, year and the year to start from 1940. This is not the case.

The select boxes are displayed as: CURRENT YEAR, CURRENT MONTH and CURRENT DAY.

How can I display just the select boxes for the year and month?


Solution

  • You should have a look at this: http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-date_select

    date_select(object_name, method, options = {}, html_options = {})

    There should be the method as second parameter and then the options. Also I found on the documentation the option :discard_day, which doesn't display the select for the day.