StYerk
2008-Jun-25 11:27 UTC
ActiveRecord::Validations::ClassMethods.evaluate_condition missing in Rails 2.1.0 ???
Hi, I have trustfully updated my Rails-Application from 2.0.2 to 2.1.0 and stumbled over the fact, that a public interface method simply has disappeared! I use a custom validation I wrote myself which gets mixed into Activerecord::Base. The validation uses the class method ''evaluate_condition'' of ActiveRecord::Validations::ClassMethods. This worked fine as of rails 2.0.2; Now I get the error ''method not found'' when I use the validation. The method really does not exist anymore. I use the method as suggested in many places for the evaluation the :if-clause of my validator. Is there any replacement for this method? How do I solve this problem? And also some general questions: How can it be that interface methods get silently deleted in a minor release step ?? And, even worse, not document it anywhere or provide a way for the user to bring their source up to date ?? I have searched myself silly, and not found any hint on this issue... Am I the only one running into that? I can hardly believe that.... Thank you for helping, Regards, Jörg --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-25 11:46 UTC
Re: ActiveRecord::Validations::ClassMethods.evaluate_condition missing in Rails 2.1.0 ???
On Jun 25, 12:27 pm, StYerk <yergy...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi, > > I have trustfully updated my Rails-Application from 2.0.2 to 2.1.0 and > stumbled over > the fact, that a public interface method simply has disappeared! > > I use a custom validation I wrote myself which gets mixed into > Activerecord::Base. > The validation uses the class method ''evaluate_condition'' of > ActiveRecord::Validations::ClassMethods. > This worked fine as of rails 2.0.2; > Now I get the error ''method not found'' when I use the validation. The > method really does not exist anymore.Refactored into ActiveSupport::Callbacks. Looks like more of an implementation detail to me, it''s unfortunate it was ever public (given that there were no tests for that specific function it doesn''t look like it was intended as a public interface). Fred> > I use the method as suggested in many places for the evaluation > the :if-clause of my validator. > > Is there any replacement for this method? How do I solve this problem? > > And also some general questions: > How can it be that interface methods get silently deleted in a minor > release step ?? > And, even worse, not document it anywhere or provide a way for the > user to bring their source up to date ?? > I have searched myself silly, and not found any hint on this issue... > > Am I the only one running into that? > I can hardly believe that.... > > Thank you for helping, > > Regards, > Jörg--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
StYerk
2008-Jun-25 13:57 UTC
Re: ActiveRecord::Validations::ClassMethods.evaluate_condition missing in Rails 2.1.0 ???
Hi Fred, Thank you for your fast answer! Actually, the scope in which I use it is in a validator that gets mixed into ActiveRecord::Base, so actually it would not even need to be public (Am I wrong?). But since I have seen this method being used in many examples for custom made validators this refactoring should be documented somewhere and how people have to rewrite their code. How do I have to rewrite my validator now? Here''s what I used with 2.0.2: ===module PresenceOneOf def self.included(base) base.extend(ClassMethods) end module ClassMethods def validates_presence_one_of(*attr_names) is_valid= true configuration= { :message => nil, :on => :save } configuration.update(attr_names.pop.symbolize_keys) if attr_names.last.is_a?(Hash) configuration[:message]= "One of the fields " + attr_names.join(",") + " must be non-empty!" send(validation_method(configuration[:on])) do |record| unless configuration[:if] and not evaluate_condition(configuration[:if], record) if attr_names.all? { |attr| record.send(attr).blank? } is_valid= false record.errors.add_to_base(configuration[:message]) end end end is_valid end end end === Thanks again, Many Regards, Jörg> Refactored into ActiveSupport::Callbacks. Looks like more of an > implementation detail to me, it''s unfortunate it was ever public > (given that there were no tests for that specific function it doesn''t > look like it was intended as a public interface). > > Fred >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jun-25 14:08 UTC
Re: ActiveRecord::Validations::ClassMethods.evaluate_condition missing in Rails 2.1.0 ???
On 25 Jun 2008, at 14:57, StYerk wrote:> > > Hi Fred, > > Thank you for your fast answer! > > Actually, the scope in which I use it is in a validator that gets > mixed into > ActiveRecord::Base, so actually it would not even need to be public > (Am I wrong?). > But since I have seen this method being used in many examples for > custom made validators > this refactoring should be documented somewhere and how people have to > rewrite their code. > > How do I have to rewrite my validator now? >I''d have a look at what other validations do. When you''ve got your head around it write it up somewhere :-) Fred> Here''s what I used with 2.0.2: > > ===> module PresenceOneOf > > def self.included(base) > base.extend(ClassMethods) > end > > module ClassMethods > def validates_presence_one_of(*attr_names) > is_valid= true > configuration= { :message => nil, :on => :save } > configuration.update(attr_names.pop.symbolize_keys) if > attr_names.last.is_a?(Hash) > configuration[:message]= "One of the fields " + > attr_names.join(",") + > " must be non-empty!" > > send(validation_method(configuration[:on])) do |record| > unless configuration[:if] and not > evaluate_condition(configuration[:if], record) > if attr_names.all? { |attr| record.send(attr).blank? } > is_valid= false > record.errors.add_to_base(configuration[:message]) > end > end > end > is_valid > end > end > > end > ===> > Thanks again, > > Many Regards, > Jörg > > > >> Refactored into ActiveSupport::Callbacks. Looks like more of an >> implementation detail to me, it''s unfortunate it was ever public >> (given that there were no tests for that specific function it doesn''t >> look like it was intended as a public interface). >> >> Fred >> > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---