ruby on rails-资产管道



我在生产模式下遇到资产管道问题。我在开发中运行了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

应用程序.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 .
 */

我有另一个与sass相关的应用程序.css.scss:

@import "compass";
@import "compass/utilities/tables";
.ftr-ticker {
  background: #333;
  height: 25px;
  width: 100%;
}
....

您修改了清单文件application.css,我认为这会带来问题。我的建议是将您的scss文件重命名为其他名称,而不是application(可能是custom.css.scss),并将其包含在清单application.css文件中,如下所示:

*= require custom

正如您所看到的,样式表文件的名称没有前缀。您的*= require bootstrap.scss应该是*= require bootstrap。我也建议在所有其他要求之后移动require_tree。本Railsguide将帮助您使用Rails3.2中的资产管道。

相关内容

  • 没有找到相关文章

最新更新