How to render images in rails3 select

邮差的信 提交于 2019-12-20 01:42:21

问题


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.



来源:https://stackoverflow.com/questions/15522965/how-to-render-images-in-rails3-select

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