Roman Gonzalez
2007-Jul-27 22:44 UTC
ActiveRecord Warnings plugin: Problem when extending ActiveRecord::Base
Hi everyone. I''m trying to make something cool with the ActiveRecord, it consists in adding the feature of warnings to it. for example: class Person < ActiveRecord::Base should_warn_presence_of :name end>> p = Person.new >> p.save=> false>> p.warned?=> true>> p.warnings.on(:name)=> ''should not be blank''>> p.accept_warnings >> p.save=> true It makes the warning about an attribute, and the only way to save it is that you confirm that you accept the warnings. When I''m trying to overwrite the validation functionality to handle the warnings and the validations of the model... the overwrite doesn''t work. I imagine that this is happening because they use the "alias_method_chain :save, :validation" on the Validation module, when I try to do this in a plugin to change the behavior of this method module ActiveRecord module Validations def save_with_validation(perform_validation = true) # code to handle the warnings end end end it doesn''t get overwritten. Maybe some dark magic is going on in the save_with_validation and the alias_method_chain. Anyone has an idea? thanks in advance PD: if someone wants to see the code, pastie can help Roman.- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Roman Gonzalez
2007-Jul-27 23:33 UTC
Re: ActiveRecord Warnings plugin: Problem when extending ActiveRecord::Base
When I execute the @person.save_with_validation, it works like a charm, but no when I invoke @person.save probably there are to many alias_method_chain on the save method that maintains a reference to the old method of save_with_validation. Does that makes sense? Roman Gonzalez wrote:> Hi everyone. > > I''m trying to make something cool with the ActiveRecord, it consists > in adding the feature of warnings to it. > for example: > > class Person < ActiveRecord::Base > should_warn_presence_of :name > end > > >> p = Person.new > >> p.save > => false > >> p.warned? > => true > >> p.warnings.on(:name) > => ''should not be blank'' > >> p.accept_warnings > >> p.save > => true > > It makes the warning about an attribute, and the only way to save it > is that you confirm that you accept the warnings. > > When I''m trying to overwrite the validation functionality to handle > the warnings and the validations of the model... the overwrite doesn''t > work. > > I imagine that this is happening because they use the > "alias_method_chain :save, :validation" on the Validation module, > > when I try to do this in a plugin to change the behavior of this > method > > module ActiveRecord > module Validations > def save_with_validation(perform_validation = true) > # code to handle the warnings > end > end > end > > it doesn''t get overwritten. > > Maybe some dark magic is going on in the save_with_validation and the > alias_method_chain. > > Anyone has an idea? > thanks in advance > PD: if someone wants to see the code, pastie can help > Roman.---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---