我在文章 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/