Format DateTime in Text Box in Rails

前端 未结 7 1830
生来不讨喜
生来不讨喜 2021-01-31 18:59

Is there an easy way to format the display of a DateTime value in a Rails view?

For example, if I\'m doing something like:

<%= text_field         


        
7条回答
  •  清歌不尽
    2021-01-31 19:38

    If your form is tied to an object, (something like <% form_for(:object) do |f| %>) you should use <%= f.text_field :start_date, :value => f.object.start_date.to_s(:date_format) %>

    then you can register your :date_format in config/environment.rb

    Not sure why you want to do this, but i hope it's for presentation purposes only.

提交回复
热议问题