LoginSignup
26
27

More than 3 years have passed since last update.

【Rails】日付入力フォームをカレンダー式にしたい(date型, datetime型)

Last updated at Posted at 2019-07-28

Railsの日付入力をカレンダー式で入力したいと思った(date型)

完成イメージ

ezgif.com-video-to-gif.gif

背景

最初、以下のように date_select で書いていたのですが

<%= form.date_select :sample_at, Date.today %>

こんな感じになってなんかイケてなかったので

スクリーンショット 2019-07-29 2.02.19.png

以下に変更

<%= form.date_field :sample_at %>

ezgif.com-video-to-gif.gif

追記(datetime型の場合はこっち)

<%= form.datetime_field :sample_at %>

参考
https://qiita.com/yatakan/items/3a359b2beef28fedb3c5
https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-date_field
https://qiita.com/pyon_kiti_jp/items/747496d02bdb1eff1ce8

26
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
27