RoR3 - 图像路径错误?

时间:2011-05-27 12:53:46

标签: 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.5ms) 渲染布局/ _usernav.html.erb(1.3ms) 在布局/应用程序中呈现文章/ index.html.erb(190.1ms) 在289ms完成200 OK(浏览次数:193.7ms | ActiveRecord:3.6ms)

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

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

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

于5月27日星期五13:44:43 +0100 2011年开始获取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.7ms)内

2 个答案:

答案 0 :(得分:4)

你的路径不正确,应该是:

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

你需要领先的/,就像你的标记一样,你也不需要在你的CSS中打勾。

答案 1 :(得分:-1)

使用相对链接:

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

这将考虑您部署到子URI的情况(例如:www.example.org/myapp /)