Rails collection_check_boxes 在生成的复选框中包含 ActiveStorage 图像
Rails collection_check_boxes include ActiveStorage image in generated checkbox
假设如下class
class Option
has_one_attached :photo
end
= collection_check_boxes(:post, :option_ids, Option.all, :id, :name) do |option|
.checkbox
= option.check_box(class: "check")
= option.photo
= option.label
我希望能够在每个复选框旁边添加一张图片,但我找不到记录在案的方法来做到这一点。有什么方法可以包含图片吗?
= collection_check_boxes(:post, :option_ids, Option.all, :id, :name) do |option|
.checkbox
= option.check_box(class: "check")
= image_tag(option.object.photo)
= option.label
There are also three special methods available: object, text and value, which are the current item being rendered, its text and value methods, respectively.
- https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes
假设如下class
class Option
has_one_attached :photo
end
= collection_check_boxes(:post, :option_ids, Option.all, :id, :name) do |option|
.checkbox
= option.check_box(class: "check")
= option.photo
= option.label
我希望能够在每个复选框旁边添加一张图片,但我找不到记录在案的方法来做到这一点。有什么方法可以包含图片吗?
= collection_check_boxes(:post, :option_ids, Option.all, :id, :name) do |option|
.checkbox
= option.check_box(class: "check")
= image_tag(option.object.photo)
= option.label
There are also three special methods available: object, text and value, which are the current item being rendered, its text and value methods, respectively.
- https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes