【问题标题】:Rails HAML assets precompile with initialize_on_precompile falseRails HAML 资产使用 initialize_on_precompile false 预编译
【发布时间】:2013-06-02 05:46:43
【问题描述】:

我在这里有点发疯了。

我在 2 个环境(暂存、生产)中有 2 个服务器(heroku,相同的配置)。

Staging 按需编译我的 /assets/templates 并毫无问题地缓存它。 生产提供未编译为 html 的文件(作为 haml 标记)

问题是:2个环境的配置是一样的(邮件服务器除外)

gems、环境配置和yml都是一样的。

有什么想法吗?

更新:

在两台服务器上“预编译”但原始的 haml 资产。暂存不会丢失文件并重新编译,因为资产是为生产而编译的。

现在我坚持将haml 添加到资产编译管道中,并且initialize_on_precompile 为false。

staging.rb / production.rb

config.cache_classes = true

config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

config.serve_static_assets = true

config.static_cache_control = "public, max-age=2592000"

config.assets.compress = true
config.assets.compile = true

config.assets.digest = true

config.assets.precompile += %w( jquery.js modernizr+respond.js polyfills.js )
config.assets.precompile += %w( gp.js ad.js richmarker.js infobox.js )

config.assets.css_compressor = :yui
config.assets.js_compressor = :uglifier
config.assets.compress=true

config.threadsafe! unless $rails_rake_task

config.i18n.fallbacks = true

config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO')

config.active_support.deprecation = :notify

config.action_dispatch.rack_cache = {
  :metastore    => Dalli::Client.new,
  :entitystore  => 'file:tmp/cache/rack/body',
  :allow_reload => false
}

Haml::Template.options[:ugly] = true

【问题讨论】:

  • 那是一个棘手的问题。预编译器从未完成对 haml 资产的编译。并且在运行时编译为他们提供服务。

标签: ruby-on-rails heroku haml assets


【解决方案1】:

解决方案是将haml添加到负载中。将以下内容添加到 application.rb

Sprockets.register_engine '.haml', Tilt::HamlTemplate

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多