How to add data attribute for options_from_collection_for_select in rails

后端 未结 1 1197
没有蜡笔的小新
没有蜡笔的小新 2021-02-18 13:53

Consider this as my select tag

<%= select_tag \"post[brand_slug]\", options_from_collection_for_select(@products, \'slug\', \'name\'), prompt: \'select\' %>         


        
相关标签:
1条回答
  • 2021-02-18 14:41

    Try following:

    <%= select_tag "post[brand_slug]", options_for_select(@products.map{ |product| [product.name, product.slug, { 'data-id' => product.id }] }), prompt: 'select' %>
    
    0 讨论(0)
提交回复
热议问题