问题
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