I want to render dropdown list in form with images as options. How to achieve this in rails3?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I like the msdropdown. You can add the path for the image in the title
tag:
<select>
<option value="1" title="#path for the image">first</option>
<option value="2" title="#path for the image">second</option>
...
</select>
In Rails, you can add the title doing something like:
<%= f.select(:yourcolumn, Model.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]}
I have faced a similar problem some time ago: generate HTML <select> with title inside each <option> to apply the msDropDown plugin
回答2:
Check out this plugin http://www.marghoobsuleman.com/jquery-image-dropdown there is no option to do it directly in Rails.