Rails date format in a text_field

后端 未结 14 2188
傲寒
傲寒 2020-12-13 06:05

I have a rails form that displays a date in a text_field:

<%= form.text_field :check_in_date  %>

The date is rendered as yyyy-m

14条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-13 06:42

    A slight improvement of Tom Rossis answer is to use the I18n.localize method, so the default will always be in the current users locale:

    initializers/date_time_i18n_formatter.rb

    Date::DATE_FORMATS[:default] = ->(date) { I18n.localize date, format: :default }
    Time::DATE_FORMATS[:default] = ->(time) { I18n.localize time, format: :default }
    

提交回复
热议问题