我开始玩Rails4,我无法让资产管道正常工作。我的网站在我的暂存环境中正常加载,除了我的css或js没有像Rails 3那样被组合或缩小。版本之间是否有某些变化?
这是我的staging.rb环境文件:
MyApp::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.cache_store = :dalli_store
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
答案 0 :(得分:2)
这是由我身上的一个问题引起的。不知何故,我将我的服务器上的环境变量设置为'development',因此它永远不会运行此暂存文件......
关于@ frandroid的回答,您不想设置
config.assets.compile = true
因为它将懒惰地编译生产中的资产。您应确保在将文件推送到服务器期间或之前完全编译它们,以确保最佳性能。
这是我最后的staging.rb文件:
MyApp::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.cache_store = :dalli_store, ENV["MEMCACHIER_SERVERS"].split(","),
{:username => ENV["MEMCACHIER_USERNAME"],
:password => ENV["MEMCACHIER_PASSWORD"]}
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end