我正在使用carrierwave gem 将图像上传到我的应用程序。
现在我需要在作为表单一部分的下拉列表中显示图像。
我正在尝试使用 msDropDown 。但是,我需要生成一个 title="#path for the image"
每个里面<option>
我的<select>
.
目前我有:
<%= f.select(:style_id, Style.all.map{ |p| [p.dropdown, p.id] }, {:include_blank => 'Select Style | Construction'}, class: "bigselect" ) %>
上面生成了以下 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>
我需要编辑我的 RoR 选择代码以生成下面的 HTML。
<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>
#path for the image
是列 image
与 dropdown
相同的型号我选择的列。因此,使用载波应该类似于 p.image_url(:thumb)
.
关于如何生成这个的任何想法 title
?
非常感谢。
最佳答案
尝试将标题作为 html 选项传递给 <option>
元素
<%= f.select(:style_id, Style.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]}, ....
关于jquery - 生成 HTML <select>,每个 <option> 内带有标题以应用 msDropDown 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11050128/