LoginSignup
22
17

More than 3 years have passed since last update.

[Rails] select, optionでinclude_blank(空白)とselectedを同時に設定する方法

Posted at

select, option使用時にinclude_blank(空白)selected(初期値)
同時に設定したかったができなかった。

しかし、以下のように設定したら解決した。

 <%= select_tag なにか,
     options_for_select(値, selected: 値),
     include_blank: true,
     class: "example" %>

options_for_select設定時は、

selected:options_for_selectの第2引数
include_blank:select_tagの第3引数

に設定しなければならない。

それまでは、selectedもselect_tagの第3引数に設定していた。


おわり

22
17
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
22
17