将此视为我的选择标签
<%= select_tag "post[brand_slug]", options_from_collection_for_select(@products, 'slug', 'name'), prompt: 'select' %>
这工作正常,但我需要一个数据属性
<%= select_tag "post[brand_slug]", options_from_collection_for_select(@products, 'slug', 'name'), data: {id: @products.id} , prompt: 'select' %>
@product.id
不管用。我怎样才能得到ID
too
尝试以下操作:
<%= select_tag "post[brand_slug]", options_for_select(@products.map{ |product| [product.name, product.slug, { 'data-id' => product.id }] }), prompt: 'select' %>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)