LoginSignup
4
1

More than 5 years have passed since last update.

ActionView の options_for_select でアイテムによって disabled にしたりしなかったりする方法

Last updated at Posted at 2018-05-14

やりかた1

options_for_select([
  ['item 1', '1'],
  ['item 2', '2'],
  ['item 3', '3'],
  ['item 4', '4'],
], disabled: [1, 4])

やりかた2

これでもいける

options_for_select([
  ['item 1', '1', disable: true],
  ['item 2', '2', disable: false],
  ['item 3', '3', disable: false],
  ['item 4', '4', disable: true],
])

See also ActionView::Helpers::FormOptionsHelper#options_for_select
いろんな書き方がありすぎる…

付録

一括で disabled にするのはこれで

options_for_select(items, disabled: true)
4
1
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
4
1