Rails date select options?

17,700

I think it should be:

<%= f.date_select :dateinstructed, :order => [:day, :month, :year] %>

Hopefully it helps.

Share:
17,700
dannymcc
Author by

dannymcc

please delete me

Updated on June 04, 2022

Comments

  • dannymcc
    dannymcc almost 2 years

    I have a date_select field in my rails application as follows:

    <%= f.date_select :dateinstructed %>
    

    I would like to re-order the drop down lists show they output as:

    DD/MM/YYYY
    

    According to what I have read you can use the :order option, but I am unsure how to actually use this option:

    <%= f.date_select :dateinstructed, :order = {:day, :month, :year} %>
    

    Obviously this isn't right, but what am I supposed to put in place of the:

    :day, :month, :year
    

    Any help would be appreciated!

    Thanks,

    Danny

  • Salil
    Salil almost 14 years
  • dannymcc
    dannymcc almost 14 years
    Thanks, the reason I couldn't get it working was this line of the API link you showed me: date_select(object_name, method, options = {}, html_options = {}) I was using options = {} not options = []
  • Tony Fontenot
    Tony Fontenot almost 14 years
    Well, not really... You were using options = {} but it was hidden from you. The form helper functions in rails will assume all the parameters passed after the required parameters to be a hash unless both the options and html_options are implicitly passed in. So in your case, after rails does it's parameter fun tricks, you are passing this f.date_select :dateinstructed, { :order => [:day, :month, :year] }, {}. That is why, when you want html options you have to close the options in curly braces ({}).