2013-02-10 218 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