如何在开发模式下避免资产消息

时间:2013-03-06 10:26:16

标签: ruby-on-rails-3.2 asset-pipeline

Started GET "/assets/reset.css?body=1" for 70.63.17.68 at Wed Oct 12 20:10:49 +0000 2011
Served asset /reset.css - 304 Not Modified (1ms)


Started GET "/assets/style.css?body=1" for 70.63.17.68 at Wed Oct 12 20:10:49 +0000 2011
Served asset /style.css - 304 Not Modified (0ms)


Started GET "/assets/application.css?body=1" for 70.63.17.68 at Wed Oct 12 20:10:49 +0000 2011
Started asset /application.css - 304 Not Modified (0ms)


Started GET "/assets/application.js?body=1" for 70.63.17.68 at Wed Oct 12 20:10:49 +0000 2011
Served asset /application.js - 200 OK (1ms)

我想避免这些消息,如果我关闭调试模式,

config.assets.debug = off  

资产文件将作为连接使用。

无论如何都要摆脱这些消息以及资产应该提供单独的资产文件。

2 个答案:

答案 0 :(得分:1)

在您的gemfile上使用gem 'quiet_assets'

group :development do
  gem 'sqlite3'
  gem 'quiet_assets'
end

答案 1 :(得分:0)

配置/初始化/ quite_assets.rb

if Rails.env.development?
  Rails.application.assets.logger = Logger.new('/dev/null')
    Rails::Rack::Logger.class_eval do
      def call_with_quiet_assets(env)
        previous_level = Rails.logger.level
        Rails.logger.level = Logger::ERROR if env['PATH_INFO'] =~ %r{^/assets/}
        call_without_quiet_assets(env)
      ensure
        Rails.logger.level = previous_level
      end
    alias_method_chain :call, :quiet_assets
  end
end