Rails date format in a text_field

后端 未结 14 2202
傲寒
傲寒 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:48

    Go to your environment.rb file and add the following:

    ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!(
      :default => '%m-%d-%Y' ) 
    

    Check the official documentation if you feel like reading more :)

提交回复
热议问题