我想以简单的形式关联在礼物上显示图像
我使用label_method
尝试了此代码,但是它不起作用:
<%=f.association :gift, :collection=> Gift.all, :label_method=>lambda { |gift| "#{gift.name} #{image_tag 'gift.photo.url(:small)'}" }, :value_method=> :id, :as=>:radio_buttons%>
此代码可以帮助您,显示带有图像的复选框
<%= f.association :gift,
:as => :check_boxes,
item_wrapper_tag: :div,
item_wrapper_class: "image-select",
:collection => Gift.all,
:label => false,
:inline_label => false,
:include_blank => false,
:input_html => {multiple: true},
:label_method => lambda { |b| image_tag(b.photo.url) },
value_method: :id
%>
如果使用字符串,请不要忘记使用html_safe