[英]Using multiple class in image_tag helper in ruby on rails
如何在Rails 5應用程序中將多個類傳遞給image_tag
助手? 我想轉換此HTML <img>
標記:
<img class="etalage_thumb_image" src="images/m1.jpg" class="img-responsive" />
成
<%= image_tag @post.picture.url if @post.picture? %>
使用Rails image_tag
幫助程序。 我該如何做到這一點?
雖然示例中的img
不是有效的,但您可以嘗試:
<% if @post.picture %> # To check if @post.picture isn't nil
<%= image_tag @post.picture.url, class: 'etalage_thumb_image img-responsive' %>
<% end %>
由空格分隔的多個類。
您的HTML 無效 。 它應該是:
<img class="etalage_thumb_image img-responsive" src="images/m1.jpg" />
...否則第二class
屬性會覆蓋第一class
屬性。
可能的方法:
<% if @post.picture %>
<%= image_tag @post.picture.url, class: "etalage_thumb_image img-responsive" %>
<% end %>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.