I would like to override the destroy method of my AR objects with something like this: module Restorable alias_method :really_destroy, :destroy def destroy self.destroyed = Date.today self.save(false) self end def restore self.destroyed = nil self.save(false) self end end Problem is that Restorable doesn''t have a destroy method to alias_method. Is there a way to get this sort of functionality? I would like to avoid adding a new method (like delete) to save confusion and so I don''t have to go back and change my controllers. Thanks, --Dean --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi,> Problem is that Restorable doesn''t have a destroy method to > alias_method. Is there a way to get this sort of functionality?everytime a module is included as a mix-in, the method "included" of the module is called, and the class including the module is passed as a parameter, so you can practice any kind of ruby dynamic black magic over the original class, in your case an AR object. I''m pasting a small template you can use for yor mix-in def self.included(parent_class) class << parent_class #everything you do here will be evaluated on the parent class content, so any method aliasing and/or overwriting should be done here end end regards, javier ramirez -- -------- Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You might want to look at acts_as_paranoid: http://ar-paranoid.rubyforge.org/ though I guess that doesn''t give you a restore method.... b Dean wrote:> I would like to override the destroy method of my AR objects with > something like this: > > module Restorable > > alias_method :really_destroy, :destroy > > def destroy > self.destroyed = Date.today > self.save(false) > self > end > > def restore > self.destroyed = nil > self.save(false) > self > end > > end > > Problem is that Restorable doesn''t have a destroy method to > alias_method. Is there a way to get this sort of functionality? I > would like to avoid adding a new method (like delete) to save > confusion and so I don''t have to go back and change my controllers. > > Thanks, > --Dean > > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 9, 11:07 am, Ben Munat <bmu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You might want to look at acts_as_paranoid: > > http://ar-paranoid.rubyforge.org/ > > though I guess that doesn''t give you a restore method.... > > bThanks for the reply. I''ll extend a_a_paranoid to include a restore method. Thanks also to javier. --Dean> Dean wrote: > > I would like to override the destroy method of my AR objects with > > something like this: > > > module Restorable > > > alias_method :really_destroy, :destroy > > > def destroy > > self.destroyed = Date.today > > self.save(false) > > self > > end > > > def restore > > self.destroyed = nil > > self.save(false) > > self > > end > > > end > > > Problem is that Restorable doesn''t have a destroy method to > > alias_method. Is there a way to get this sort of functionality? I > > would like to avoid adding a new method (like delete) to save > > confusion and so I don''t have to go back and change my controllers. > > > Thanks, > > --Dean--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---