404 when displaying background image in CSS with rails 3.2

青春壹個敷衍的年華 提交于 2019-12-11 06:17:37

问题


I manually added assets/images directory in a rails 3.2 app and added the image background.png . When referring to the image from css

background: url("assets/background.png") no-repeat;

I am getting a 404 , however assets/stylesheets and assets/javascripts are showing up.

**UPDATE

it appears as if I revert back to explicitly calling the stylesheet ie

<%=stylesheet_link_tag "home.css"%> 

instead of

<%=stylesheet_link_tag "application" %>

The background image reders correctly


回答1:


That url is relative to where the style sheet is. You probably want either url(../assets/background.png) to go up a level from your style sheet or url(/assets/background.png) to go from the root.




回答2:


Use:

url(<%= asset_path 'background.png' %>)

and you'll be fine.



来源:https://stackoverflow.com/questions/10093077/404-when-displaying-background-image-in-css-with-rails-3-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!