after_save in plugin

Dear list,
I am trying to override an after_save callback declared in main app
using plugin.
The main model class is:

class WorkHours < ActiveRecord::Base
  @after_save_call_back_called=0
  after_save :after_save_call_back
  def after_save_call_back
    logger.debug "after save called"
    @after_save_call_back_called=1
  end
end

And in my plugin (in the lib directory) :

module WorkHoursPatch
# cattr_accessor
def self.included(base) # :nodoc:
   base.logger.debug "inlcuded called"
   base.extend(ClassMethods)
   base.send(:include, InstanceMethods)
   base.after_save.delete_if{
     >callback> callback.method == :after_save_call_back
   }
   base.send(:after_save, :after_save_call_back_patched)
end

module ClassMethods

end

module InstanceMethods
  def after_save_call_back_patched
    logger.debug "overriden after save called"
    @after_save_call_back_called=1
  end
   # Wraps the association to get the Deliverable subject. Needed for
the
   # Query and filtering
   # def is_new
   # unless self.is_new.nil?
   # return self.is_new
   # end
   # return false;
   # end
end
end

I think your issue may be a mixup with class instance and instance variables.

However, what’s the issue you are having with all this? Are you getting any error messages?

Thanks Tom ,
I have actually figured out the problem.

Seems like since the lib of the plugin is not reloaded on every request

but the main app is .The plugin override works for first request but the

original methods are restored the next one.

The solution that worked for me was wrapping our monkey-patch in a callback.

http://theadmin.org/articles/how-to-modify-core-redmine-classes-from-a-plugin/

Evgeny