How to set default date in date_select helper in Rails

前端 未结 1 509
别跟我提以往
别跟我提以往 2021-01-03 09:09

I\'m trying to set up a date of birth helper in my Rails app (2.3.5). At present it is like so.

<%= f.date_select :date_of_birth, :start_year => Time.n         


        
相关标签:
1条回答
  • 2021-01-03 09:11

    I think that easiest way is to assign it in controller, for example for new action:

    @person = Person.new(:date_of_birth => "2010-01-01".to_date)
    

    Then in your view you will get correct date.

    EDIT:
    If you want to assign default value on model level, you can try do it with plugin. However I haven't try it.

    0 讨论(0)
提交回复
热议问题