LoginSignup
0
0

More than 3 years have passed since last update.

collection_selectにデフォルト値で空欄を設定する方法

Posted at

環境 rails 5.2.3 ,ruby 2.5.1

先に結論から

include_blank: true
を付ける!

付け方(例)

= i.collection_select :month_id, Month.all, :id, :name, include_blank: true

view画面では

スクリーンショット 2020-03-07 1.03.58.png
見事空欄が表示できた!

0
0
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
0
0