我想显示带有复选框的实例集合。这个实例是图像所以不是显示id我想显示他们的图像。我正在使用回形针,所以基本用法是image_tag model.image.url
这是我的代码(根据此来源:Add Image Tag to Checkbox Input Field with Rails 4 and Simple Form):
= f.input_field :inspiration_image_ids,
:collection => InspirationImage.all.each {|i| "#{image_tag('image.url')}".html_safe },
:include_blank => '(All)',
:multiple => true,
:selected => [''],
as: :check_boxes
这或多或少是我想要的:
答案 0 :(得分:1)
使用地图,而不是每个。
console.log(err);
throw err;
此外,我将其设为InspirationImage.all.map {|i| image_tag(i.url).html_safe },
而不是文字(i.url)
字符串,只需使用普通的旧image_tag即可,无需将其包装在字符串中。