generate HTML <select> with title inside each <option> to apply the msDropDown plugin

我只是一个虾纸丫 提交于 2020-01-04 02:53:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!