【问题标题】:rails html image_tag not rendering classesrails html image_tag不呈现类
【发布时间】:2016-02-03 19:26:35
【问题描述】:

我正在用 Ruby on Rails 构建一个博客应用程序。我有一个“关于”视图,我想在其中加载图像并使用一些引导类对其进行样式设置。

目前,图像已成功加载并在页面上呈现,但它没有我想要的样式,当我使用 Chrome Inspector 时,我看到浏览器完全忽略了类(跳过它们)。

我正在从一个基本网页移植这个项目,在将它移植到 Rails 之前,图像的样式是正确的。

这是我的 Rails 代码:

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

这就是 Chrome Inspector 看到的:

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

没有课!他们去哪儿了?

这是我的旧页面中的 HTML 代码,它有效:

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

如果您有一双新鲜的眼睛,我们将不胜感激。我错过了什么?

【问题讨论】:

    标签: html css ruby-on-rails ruby


    【解决方案1】:

    尝试在 asset_path 方法的参数周围加上括号:

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

    【讨论】:

      猜你喜欢
      • 2014-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多