如何在Rails3中渲染图像 [英] How to render images in rails3 select

查看:126
本文介绍了如何在Rails3中渲染图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以图像作为选项以表格形式显示下拉列表.如何在rails3中实现这一目标?

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

推荐答案

我喜欢 msdropdown .您可以在title标签中添加图像的路径:

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>

在Rails中,您可以添加标题,例如:

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

这篇关于如何在Rails3中渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆