如何image_tag
在 Rails 5 应用程序中将多个类传递给助手?我想转换这个 HTML<img>
标签:
<img class="etalage_thumb_image" src="images/m1.jpg" class="img-responsive" />
进入
<%= image_tag @post.picture.url if @post.picture? %>
使用 Railsimage_tag
助手。我该如何做到这一点?
如何image_tag
在 Rails 5 应用程序中将多个类传递给助手?我想转换这个 HTML<img>
标签:
<img class="etalage_thumb_image" src="images/m1.jpg" class="img-responsive" />
进入
<%= image_tag @post.picture.url if @post.picture? %>
使用 Railsimage_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
属性会覆盖第一个属性。
可能的解决方案:
<% if @post.picture %>
<%= image_tag @post.picture.url, class: "etalage_thumb_image img-responsive" %>
<% end %>