Rails预编译资产-无法在本地访问预编译的文件
我的Rails应用程序中有一个神秘的问题,我无法解决.
I have a mysterious problem in my rails application, which I cannot fix.
问题是,我想预编译CSS和JavaScript,并在部署到服务器之前在暂存环境中本地运行服务器,以检查一切是否正常.
The thing is that I want to precompile my CSS and JavaScripts and run the server on the staging environment locally to check if everything is ok, before I deploy to the server.
我运行以下命令来预编译文件:
I run this command to precompile the files:
rake assets:precompile RAILS_ENV=staging
要在登台环境中启动服务器,请运行以下命令:
To start the server in staging environment i run this command:
rails s -e staging
文件已成功预编译并放置在public/assets文件夹中,但无法在浏览器中加载,我也无法从浏览器手动访问文件.
The files are being precompiled successfully and placed in the public/assets folder, but can not be loaded in the browser, and I cannot access the files manually from the browser either.
我的staging.rb环境文件如下:
My staging.rb environment file looks like this:
# 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
config.static_cache_control = "public, max-age=2592000"
config.action_controller.perform_caching = true
# Compress JavaScripts and CSS
config.assets.compress = true
config.assets.debug = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.assets.initialize_on_precompile = true
# Use a different cache store in production
#config.cache_store = :dalli_store, 'localhost:11211'
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( .svg .eot .woff .ttf )
在使用以下版本的红宝石和铁轨时:
In using following versions of ruby and rails:
Ruby v.1.9.3 Rails v.3.2.14
Ruby v. 1.9.3 Rails v. 3.2.14
通过注释以下行解决了该问题:
Solved the problem by outcommenting the line:
config.serve_static_assets = false