问题
I am using the carrierwave gem to upload images to my application.
Now I need to display the images in a dropdown list that is part of a form.
I am trying to use the msDropDown. However, I need to generate a title="#path for the image"
inside each <option>
of my <select>
.
At the moment I have:
<%= f.select(:style_id, Style.all.map{ |p| [p.dropdown, p.id] }, {:include_blank => 'Select Style | Construction'}, class: "bigselect" ) %>
The above generates the following HTML:
<select class="bigselect" id="item_style_id" name="item[style_id]"><option value="">Select Style | Construction</option>
<option value="1">first</option>
<option value="2">second</option>
...
</select>
I need to edit my RoR select code to generate the HTML below.
<select class="bigselect" id="item_style_id" name="item[style_id]"><option value="">Select Style | Construction</option>
<option value="1" title="#path for the image">first</option>
<option value="2" title="#path for the image">second</option>
...
</select>
The #path for the image
is the column image
on the same Model as the dropdown
column on my select. So, using carrierwave should be something like p.image_url(:thumb)
.
Any ideas on how to generate this title
?
Many thanks.
回答1:
Try to pass title as html options to <option>
elements
<%= f.select(:style_id, Style.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]}, ....
来源:https://stackoverflow.com/questions/11050128/generate-html-select-with-title-inside-each-option-to-apply-the-msdropdown-p