如何将类添加到 image_tag Rails 帮助程序

发布于 2024-12-17 23:25:44 字数 290 浏览 1 评论 0原文

我有以下代码:

<%= image_tag iterator.image.url(:small), :class => "img_preview" %>

但渲染的 HTML 显示:

<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452" alt="Clean_wave">

为什么“class”属性不存在?

谢谢你!

I have the following code:

<%= image_tag iterator.image.url(:small), :class => "img_preview" %>

But the rendered HTML shows:

<img src="/actives/hotels/13/small/clean_wave.jpg?1317675452" alt="Clean_wave">

Why the "class" attribute isn't there?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

A君 2024-12-24 23:25:44

您的类必须分配在括号内,才能用作传递的选项的一部分。尝试:

<%= image_tag(iterator.image.url(:small), :class => "img_preview") %>

Your class has to be assigned inside of the brackets to be used as part of the options being passed through. Try:

<%= image_tag(iterator.image.url(:small), :class => "img_preview") %>
忘你却要生生世世 2024-12-24 23:25:44

对于像我这样的新手,这里有一个带有较新的 Rails 语法的更清晰的版本:

<%= image_tag iterator.image.url(:small), class:"img_preview" %>

For newbies like myself, heres a cleaner version with the newer rails syntax:

<%= image_tag iterator.image.url(:small), class:"img_preview" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文