2015-08-09 98 views
-1

我想顯示一個簡單的圖像從我的資產圖像。我試圖在下列方式:css沒有加載圖像資產在軌道上4

#head { 
background: #181015 url(../images/header_bg.png) no-repeat; 
background-size: cover; 
min-height: 520px; 
text-align: center; 
padding-top: 240px; 
color: white; 
font-family: "Open sans", Helvetica, Arial; 
font-weight: 300; 
} 

在我assets/images文件夾我有其他的影像。如果我設置其他圖像,那麼它的工作正常。但是,如果我嘗試加載上面的圖像,那麼它無法加載該圖像。我把下面的事情我environments/development.rb

config.assets.debug = true 
config.assets.compile = true 
config.assets.precompile = ['*.js', '*.css', '*.css.erb'] 

我也跑bundle exec rake assets:precompile後來也實在是無法加載圖像。該圖像沒有任何問題。因爲我嘗試使用相同的CSS的簡單的HTML頁面,它工作正常。我錯過了什麼。需要一些幫助。

+0

http://stackoverflow.com/questions/16512080/how-can-i-reference- css-background-images-in-production-in-rails-4-0 –

回答

3

您是否嘗試過使用image-url而不是url。您可能需要更改我有這樣的合作,只是「header_bg.png」(而不是具有圖像目錄在內)的路徑

的東西一個例子:

enter image description here

您是否也嘗試重新啓動服務器,看看這是否是原因?

Rails有時處理資產的方式與您將其與基本css鏈接的方式不同。您可能需要在文檔看上去太:

http://guides.rubyonrails.org/asset_pipeline.html

大致在第2.3.2節

+0

感謝喲ufor快速回放'url(「header_bg.png」)'適合我 – nilkash