[Ruby on Rails] How to Format Time and Set Initial Values in Input Forms
In Ruby on Rails 3.2.3, I researched how to format time and set initial values in input forms, so here’s a memo.
Excerpt from the form. Write it like this:
# app/views/articles/_article_form.html.haml
%tr
%th Published Time
%td
= f.text_field :published_at, value: (f.object.published_at.blank? ? '' : f.object.published_at.strftime('%Y/%m/%d %H:%M')
That’s all from the Gemba.