From e084dc4b36336ea141fcdb87cddf99d87721cee5 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 6 Feb 2011 21:21:13 +0900 Subject: [PATCH] suppress logging when rendering each partial --- TODO.txt | 2 -- lib/kaminari/helpers.rb | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/TODO.txt b/TODO.txt index e3e85e3..3733810 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,5 @@ * partialize the outer div -* suppress logging when rendering each partial - * add generator option to copy particular template * add Haml generator diff --git a/lib/kaminari/helpers.rb b/lib/kaminari/helpers.rb index 9252788..58533af 100644 --- a/lib/kaminari/helpers.rb +++ b/lib/kaminari/helpers.rb @@ -63,8 +63,10 @@ module Kaminari end def to_s - @template.content_tag :div, :class => 'pagination' do - tagify.join("\n").html_safe + suppress_logging_render_partial do + @template.content_tag :div, :class => 'pagination' do + tagify.join("\n").html_safe + end end end @@ -96,6 +98,25 @@ module Kaminari def method_missing(meth, *args, &blk) @template.send meth, *args, &blk end + + def suppress_logging_render_partial(&blk) + if subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber} + class << subscriber + alias_method :render_partial_with_logging, :render_partial + # do nothing + def render_partial(event) + end + end + ret = blk.call + class << subscriber + alias_method :render_partial, :render_partial_with_logging + undef :render_partial_with_logging + end + ret + else + blk.call + end + end end def paginate(scope, options = {}, &block)