Help us understand the problem. What is going on with this article?


More than 5 years have passed since last update.



<%= f.collection_check_boxes :category_ids, Category.all, :id, :name do |b| %>
  <% b.label { b.check_box + b.text } %>
<% end %>

このヘルパーメソッドに渡すブロックの中で適当な属性の値を取得したい時は b.object プロパティを経由して直接レコードにアクセスすることが可能です。

<%= f.collection_check_boxes :category_ids, Category.all, :id, :name do |b| %>
  <% b.label(data-color: b.object.color) { b.check_box + b.text } %>
<% end %>
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away