2014-05-13 187 views
0

我目前的問題與本帖子中描述的完全相同:Rails not serving assets in production or staging environments未在Windows上投入生產的Rails 4資產

我在Windows 7的生產環境中運行Rails 4.0.4(所以很容易成爲問題,不能很好地使用Linux)。我運行了rake assets:clobber以確保所有內容都已清理完畢,然後RAILS_ENV=production rake assets:precompile,併成功完成,沒有錯誤或警告。所有的文件出現在我的公共/資產文件夾中,並使用Windows資源管理器,我可以查看application.js和application.css中的文本,並正確顯示圖像。但是,當我嘗試訪問localhost:3001/assets/application.js時,它與application.css相同,並且圖像文件出現錯誤。每次更改設置和預編譯後,我都重新啓動了服務器。

當我看着日誌說它的頁面呈現成功,沒有像我在其他帖子中看到的「沒有路由匹配」的錯誤。所以資產被發現,但由於某種原因,他們沒有得到適當的服務。

這裏是我的production.rb:

ABC::Application.configure do 

    config.cache_classes = true 
    config.eager_load = true 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 
    config.action_dispatch.x_sendfile_header = "X-Sendfile" 
    config.serve_static_assets = true 
    config.action_mailer.default_url_options = { :host => '' } 
    config.i18n.fallbacks = true 
    config.active_support.deprecation = :notify 
    config.assets.js_compressor = :uglifier 
    config.assets.css_compressor = :sass 
    config.assets.compile = false 
    config.assets.digest = true 

end 

任何幫助將不勝感激,我一直停留在這近兩天!

回答

0

就在我輸入完這個問題之後,我終於碰到另一篇文章,裏面說頭文件已被設置,但沒有任何內容,這聽起來像是我的問題。他們使用nginx的,並通過改變固定的問題如下:

# Specifies the header that your server uses for sending files 
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

而且看到,因爲我不使用Apache或nginx的,我註釋掉了兩條線,最後我的資產服務。事後看起來很明顯,但我認爲我會發布這個以防萬一它有幫助其他人有同樣的問題。