我有一个rails图像标记"
<%= image_tag 'how-it-works.png', {id: 'how-it-works'} %>
我还想添加引导类img-responsive
,以便图像保留在其容器中。
怎么会这样做?
我在rails docs上看到了一些选项,但它们似乎都没有工作:
image_tag("icon")
# => <img alt="Icon" src="/assets/icon" />
image_tag("icon.png")
# => <img alt="Icon" src="/assets/icon.png" />
image_tag("icon.png", size: "16x10", alt: "Edit Entry")
# => <img src="/assets/icon.png" width="16" height="10" alt="Edit Entry" />
image_tag("/icons/icon.gif", size: "16")
# => <img src="/icons/icon.gif" width="16" height="16" alt="Icon" />
image_tag("/icons/icon.gif", height: '32', width: '32')
# => <img alt="Icon" height="32" src="/icons/icon.gif" width="32" />
image_tag("/icons/icon.gif", class: "menu_icon")
# => <img alt="Icon" class="menu_icon" src="/icons/icon.gif" />
image_tag("/icons/icon.gif", data: { title: 'Rails Application' })
# => <img data-title="Rails Application" src="/icons/icon.gif" />
答案 0 :(得分:3)
image_tag(source,options = {})
source
是assets/images
目录中图像文件的名称,因此,您可以将id
和class
作为选项传递。无需使用括号(第6个示例):
<%= image_tag 'how-it-works.png', id: 'how-it-works', class: 'img-responsive' %>
呈现:
<img id="how-it-works" class="img-responsive" src="/assets/how-it-works-....png" alt="How it works">