Problem with sweepers #1

Open
MartinKoerner opened this Issue Mar 30, 2010 · 1 comment

Comments

Projects
None yet
1 participant
@MartinKoerner

Hi,

I discovered this error with ActiveScaffold:
If you have sweepers activated, you will get a NoMethodError, because Sweepers after action is called twice.
First time, it sets self.controller = nil, so second time it fails to get controller_name.

This behaviour is mentioned in http://dev.rubyonrails.org/ticket/6199, but since components were removed from rails it was never fixed there...

@MartinKoerner

This comment has been minimized.

Show comment
Hide comment
@MartinKoerner

MartinKoerner Mar 30, 2010

Fixed it with following monkey patch (I changed the suggested patch a little bit):

module ActionController
  module Caching
    class Sweeper < ActiveRecord::Observer
      attr_accessor :controller

      def initialize
        @controller_stack = []
        super
      end

      def before(controller)
        @controller_stack << controller
        self.controller = controller
        callback(:before) if controller.perform_caching
      end

      def after(controller)
        callback(:after) if controller.perform_caching
        @controller_stack.pop
        self.controller = @controller_stack.last
      end
    end
  end
end

So all Sweepers are saving all calling controllers instead of only one...

Fixed it with following monkey patch (I changed the suggested patch a little bit):

module ActionController
  module Caching
    class Sweeper < ActiveRecord::Observer
      attr_accessor :controller

      def initialize
        @controller_stack = []
        super
      end

      def before(controller)
        @controller_stack << controller
        self.controller = controller
        callback(:before) if controller.perform_caching
      end

      def after(controller)
        callback(:after) if controller.perform_caching
        @controller_stack.pop
        self.controller = @controller_stack.last
      end
    end
  end
end

So all Sweepers are saving all calling controllers instead of only one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment