0

I have an association where a Vote has many Images, and I'd like this association to be checkboxes but instead of text have an image next to the checkbox instead of a text value the an example of the outputted HTML would look like:

<input class="check_boxes optional" id="vote_image_id_1" name="vote[image_id][]" type="checkbox" value="1"><img src="boat.png" alt="Big Boat"> <br />

Is this possible to do with simple form or will I need to write a custom field for this? If i have to write a custom field could someone recommend some good resources on making custom fields with simple form.

4

1 回答 1

1

我现在无法测试它,但我或多或少会这样做:

options = []
images.each do |image|
  options << [image.id, image_tag(image.path)]
end
f.collection_check_boxes :votes, options, :first, :last

也许您可以将选项数组的构造提取到辅助方法中。

我希望它有帮助:)

于 2013-09-27T09:43:43.297 回答