简体   繁体   English

Rails html image_tag不呈现类

[英]rails html image_tag not rendering classes

I'm building a blog app in Ruby on Rails. 我正在Ruby on Rails中构建一个博客应用程序。 I have an "About" view where I'd like to load an image and style it with some bootstrap classes. 我有一个“关于”视图,我想在其中加载图像并使用一些引导程序类对其进行样式设置。

Currently, the image is loading successfully and rendering on the page, but it doesn't have the styling I want and when I use the Chrome Inspector I see that the browser is totally ignoring the classes (skips over them). 目前,图片已成功加载并呈现在页面上,但是没有我想要的样式,当我使用Chrome Inspector时,我发现浏览器完全忽略了类(跳过它们)。

I'm porting this project over from a basic web page, and before porting it to Rails, the image was styled correctly. 我正在从基本网页上移植该项目,并且在将其移植到Rails之前,图像的样式正确。

Here is my Rails code: 这是我的Rails代码:

<%= image_tag asset_path 'filename.jpg', class: "img-responsive img-rounded center-block", alt: "Image description" %>

And this is what Chrome Inspector sees: 这是Chrome Inspector看到的:

<img src="/assets/filename.jpg" alt="Image description">

No classes! 没有课! Where did they go? 他们去哪了

Here is my HTML code from the old page, which works: 这是旧页面上的我的HTML代码,可以正常工作:

<img src="assets/images/filename.jpg" class="img-responsive img-rounded center-block" alt="Image description" />

A fresh set of eyes would be appreciated. 新鲜的眼睛将不胜感激。 What am I missing? 我想念什么?

尝试将您参数的括号放在asset_path方法中:

<%= image_tag asset_path('filename.jpg'), class: "img-responsive img-rounded center-block", alt: "Image description" %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM