Rails date format in a text_field

后端 未结 14 2176
傲寒
傲寒 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

    I added these to my initializers/time_formats.rb and it works great:

    # Default format for displaying dates and times
    Date::DATE_FORMATS[:default] = "%m/%d/%Y"
    Time::DATE_FORMATS[:default] = "%m/%d/%Y"
    

    Using Ruby 1.9.3 and Rails 3.2.x

提交回复
热议问题