css - RoR3 - 图像路径错误?

标签 css ruby-on-rails-3

我在文章 p 标签内的索引页上显示了一个评论气泡的图像,显​​示已添加了多少评论。 RoR3 不断抛出错误,这让我很困惑!?

出于某种原因,它会在路径 stylesheets/images/comment.png 中查找 - 而根据 Ruby 代码块,它应该只在/images/comment.png 中查找。关于我哪里出错的任何建议?

_article.html.erb

<div class="article_header">
<b>Article Title: </b> <%= truncate(article.title, :length => 50) %> 

<div class="com-bub">
<img src="/images/comment.png"/>
</div>

<div class="com-cnt">
<%= article.comments.count %>
</div>

CSS:

.com-bub {
float:right;
background: url('images/comment.png') no-repeat;
margin: -8px 16px 0px 0px;
}

错误:

SQL (0.2ms) SELECT COUNT(*) FROM "articles"WHERE (published = 't') 渲染布局/_footer.html.erb(1.5 毫秒) 渲染布局/_usernav.html.erb(1.3 毫秒) 在布局/应用程序中呈现文章/index.html.erb(190.1 毫秒) 在 289 毫秒内完成 200 OK( View :193.7 毫秒 | ActiveRecord:3.6 毫秒)

在 2011 年 5 月 27 日星期五 13:44:43 +0100 开始为 127.0.0.1 获取“/stylesheets/images/comment.png”

在 2011 年 5 月 27 日星期五 13:44:43 +0100 开始为 127.0.0.1 获取“/stylesheets/images/comment.png”

在 2011 年 5 月 27 日星期五 13:44:43 +0100 开始为 127.0.0.1 获取“/stylesheets/images/comment.png”

在 2011 年 5 月 27 日星期五 13:44:43 +0100 开始为 127.0.0.1 获取“/stylesheets/images/comment.png”

ActionController::RoutingError(没有路由匹配“/stylesheets/images/comment.png”):

渲染/opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb 在救援/布局内(0.7 毫秒)

最佳答案

你的路径不对,应该是:

background: url(/images/comment.png) no-repeat;

你需要前导 / 就像在你的标记中一样,你也不需要在你的 css 中打勾。

关于css - RoR3 - 图像路径错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6152504/

相关文章:

ruby-on-rails-3 - Rails Bootstrap Navbar和精炼厂CMS

css - 将 CSS 字体大小/行高存储在 Sass 变量中

php - 如何动态添加图片?

jquery - 是否有任何 CSS 属性保留 .class :focus{--} property remain after clicking anywhere else than focused image

ruby-on-rails-3 - 路由在 RoR 中不起作用

ruby-on-rails - 属于一组类

css - 大图像按比例缩小, Chrome 不清晰

html - 多个 CSS 选择器

javascript - Rails 中的 ruby​​ vs js 字符串连接

ruby-on-rails - 即使清除缓存后,Favicon 也不会在生产中显示