How to render images in rails3 select

前端 未结 2 1131
半阙折子戏
半阙折子戏 2021-01-20 11:21

I want to render dropdown list in form with images as options. How to achieve this in rails3?

相关标签:
2条回答
  • 2021-01-20 12:07

    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

    0 讨论(0)
  • 2021-01-20 12:14

    Check out this plugin http://www.marghoobsuleman.com/jquery-image-dropdown there is no option to do it directly in Rails.

    0 讨论(0)
提交回复
热议问题