19
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails4 + Simple formでradio buttonインターフェースを用い且つselectedする

19
Last updated at Posted at 2014-05-27

みんな大好きsimple_formですが、公式の説明が 手抜きソース嫁がスタンスなようでして、舐めてかかると盛大にハマります。
そんな全国のsimple_formerの為に表題の件掲載しておきます。

<%= f.input :sex, collection: [["male", 1],["female", 2]], checked: 1, as: :radio_buttons, item_wrapper_class: "inline" %>

ついでに、simple_formあるあるハマりポイントの「横並びラジオボタンにしたい」はitem_wrapper_class: "inline"です。

<%= f.input :category_id, collection: Category.all.map { |c| [c.name, c.id] }, checked: item.category_ids.split(" "), as: :check_boxes %>

item.category_idsはリテラルか配列で受ける感じです

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?