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 # ## Add module to Issue WorkHours.send(:include, WorkHoursPatch) The init.rb says require ''work_hours_patch'' All this should work and running the console I an see the old plugin being deleted and the new one added. Please help! I am spending on this days! Evgeny -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/C-uGWVAUau0J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 On Mon, Jan 30, 2012 at 6:28 PM, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> 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? > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/C-uGWVAUau0J. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.