2013-02-10 215 views
1

我在生產模式中遇到了資產管道問題。我在開發中運行bundle exec rake assets:precompile,它工作正常。但是,當我在生產服務器上運行它時(部署之後),css和js文件無法正確加載。當我通過url /assets/[file_name]訪問css或js文件時,出現500錯誤。我認爲這是一個許可問題,但/public/assets下的所有文件都可以訪問。 Production.rb和development.rb文件都是完整的(來自腳手架)。我可以看到所有列在HTML中的文件。任何提示將不勝感激。由於資產管道

production.rb:

# Code is not reloaded between requests 
    config.cache_classes = true 

    # Full error reports are disabled and caching is turned on 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 

    # Disable Rails's static asset server (Apache or nginx will already do this) 
    config.serve_static_assets = false 

    # Compress JavaScripts and CSS 
    config.assets.compress = true 

    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = true 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 

的Gemfile(快照):

gem 'rails', '3.2.11' 

gem 'pg' 
gem 'json' 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer' 

    gem 'uglifier', '>= 1.0.3' 
end 

gem 'compass-rails' 
# Deployment related 
gem 'capistrano' 
gem 'capistrano-ext' 

gem 'jquery-rails', '~> 2.0.0' 
gem 'jquery-datatables-rails' 

group :development do 
    gem 'guard' 
end 

Application.css:

/* 
* This is a manifest file that'll be compiled into application.css, which will include all the files 
* listed below. 
* 
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
* 
* You're free to add application-wide styles to this file and they'll appear at the top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
*= require_self 
*= require dataTables/jquery.dataTables 
*= require bootstrap.scss 
*= require bootstrap-responsive.scss 
*= require_tree . 
*/ 

我有另一個application.css.scss社科院相關:

@import "compass"; 
@import "compass/utilities/tables"; 

.ftr-ticker { 
    background: #333; 
    height: 25px; 
    width: 100%; 
} 
.... 
+0

你可以發佈你的'application.js'和'application.css'嗎? – 2013-02-10 23:40:54

+0

我已經更新了更多信息的問題:) – kasperite 2013-02-11 00:19:10

回答

1

您已修改清單文件application.css,我認爲這會產生問題。我的建議是重命名scss文件到其他名稱,而不是application(可能是custom.css.scss),並將其列入清單application.css文件是這樣的:

*= require custom 

正如你所看到的,樣式表文件的文件名沒有前綴。你的*= require bootstrap.scss應該是*= require bootstrap。我建議在所有其他要求之後再移動require_treeThis Railsguide將在Rails 3.2中幫助您完成資產管道。

+0

嗨,謝謝你的幫助。我試過你的解決方案,但無濟於事。我想這更像是路徑錯誤,因爲我可以在html中看到諸如'/ assets/application- [hash] .css'之類的東西,但無法打開它。該文件確實存在並且具有內容。這是不是很奇怪?這是我第一次處理資產管道實際上,對不起,如果它聽起來新手 – kasperite 2013-02-11 01:38:37

+0

類似哈希的名稱是好的,這些是預先完成的資產,我想你試圖讓他們在服務器上,但你不能。我會建議你從開發中刪除你的「公共/資產」,而不是手工預編譯資產,這會攪亂開發過程。 capistrano任務處理預編譯罰款。你能顯示你放置'css.scss'文件的位置嗎? – 2013-02-11 01:52:18

+0

非常感謝Qumara SixOneTour,我發現了這個問題。它實際上是在虛擬主機設置中,公共/資產文件夾沒有正確代理到後端。儘管如此,我仍然會讚賞你的意願:D – kasperite 2013-02-11 02:35:51