如何让select_date在重新渲染时保留选定的值

时间:2018-04-18 19:27:15

标签: ruby-on-rails

我有一个date_select:

<%= f.date_select :date_of_birth, {
                  :with_css_classes => true,
                  :order => [:month, :day, :year],
                  :prompt => true,
                  start_year: Date.today.year, end_year: Date.today.year - 100}, {:class => "select"} %>

如果出现错误,并且页面重新渲染,则该值将丢失。通过常规选择我设置了参数,但我不知道如何或使用date_select

1 个答案:

答案 0 :(得分:0)

参考this,使用selected

 <%= f.date_select :date_of_birth, {
                   with_css_classes: true,
                   order: [:month, :day, :year],
                   selected: @date
                   prompt: true,
                   start_year: Date.today.year, end_year: Date.today.year - 100},
                   {:class => "select"} %>