はじめに
enumの値ごとにラジオボタンを作るのが面倒だったので、どうにかまとめられないかというのが起点。
collection_select_boxみたいなものがあればという淡い期待のもと調査をしてみます。
元のコード
= form_for object do |f|
= f.radio_button :status, 'good'
span
| Good
= f.radio_button :status, 'normal'
span
| Normal
= f.radio_button :status, 'bad'
span
| Bad
まとめる
= collection_radio_buttons(@object, :status, Object.statuses, :first, :first) do |b|
.m-form-checkbox__item
= b.radio_button + b.label