Rails each_with_index tag 使い方

 

例:

View file:

- @categories.each_with_index do |category,i|
= check_box_tag "category#{i+1}", category.id
= category.name

注意:このとき|i, category|とするとエラー。| 

 ビュー:

カテゴリーidを入れるパラメーターの名前を

category1

category2 などとできる。

 

d.hatena.ne.jp