Consider this as my select tag
<%= select_tag "post[brand_slug]", options_from_collection_for_select(@products, 'slug', 'name'), prompt: 'select' %>
This works fine but I need a data attribute
<%= select_tag "post[brand_slug]", options_from_collection_for_select(@products, 'slug', 'name'), data: {id: @products.id} , prompt: 'select' %>
@product.id
is not working. How can I get the ID
too
Try following:
<%= select_tag "post[brand_slug]", options_for_select(@products.map{ |product| [product.name, product.slug, { 'data-id' => product.id }] }), prompt: 'select' %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With