gpt4 book ai didi

ruby-on-rails - 在 ruby​​ on rails 中的 image_tag 助手中使用多个类

转载 作者:行者123 更新时间:2023-12-01 11:20:01 25 4
gpt4 key购买 nike

如何将多个类传递给 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? %>

使用 Rails image_tag helper 。我该如何做到这一点?

最佳答案

尽管示例中的 img 无效,但您可以尝试:

<% if @post.picture %> # To check if @post.picture isn't nil
<%= image_tag @post.picture.url, class: 'etalage_thumb_image img-responsive' %>
<% end %>

由空格分隔的多个类。

关于ruby-on-rails - 在 ruby​​ on rails 中的 image_tag 助手中使用多个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45001857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com