LoginSignup
1
0

More than 3 years have passed since last update.

【Rails】form_forのselectにclassとoption両方を定義したい

Last updated at Posted at 2019-01-22

 やりたいこと

form_forのf.selectでclassとoption(:include_blankや:promptなど)を定義したい。

参考にした記事

ソースコードを調べて見ると、option(:include_blankや:prompt)は第3引数に設定し、html_options(classやstyle)は第4引数に設定するようでした。

実際のコード

= f.select :l_category_id, Item.l_category_ids.keys, {prompt: "---"}, {class: "select-default" }

解説

  • :l_category_idが第一引数
  • Item.l_category_ids.keysが第二引数
  • {prompt: "---"} が第三引数
  • {class: "select-default"}が第三引数

 promptとclassを{}で囲む必要があった。

1
0
1

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