带有图像的简单格式关联标签

问题描述 投票:1回答:1

我想以简单的形式关联在礼物上显示图像

我使用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%>
ruby-on-rails ruby-on-rails-3 simple-form
1个回答
0
投票

此代码可以帮助您,显示带有图像的复选框

<%= 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

© www.soinside.com 2019 - 2024. All rights reserved.