Rails date format in a text_field

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

    Simple one time solution is to use :value option within text_field call instead of adding something to ActiveRecord::Base or CoreExtensions.

    For example:

    <%= f.text_field :some_date, value: @model_instance.some_date.strftime("%d-%m-%Y") %>
    

提交回复
热议问题