# ActiveRecord::Validations::ClassMethods.evaluate\_condition missing in Rails 2.1.0?

**URL:** <https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398>\
**Category:** Rails\
**Created:** [June 25, 2008, 1:43pm UTC](https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398 "2008-06-25T13:43:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StYerk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@StYerk](https://www.ruby-forum.com/u/StYerk)\
**Post date:** [June 25, 2008, 1:43pm UTC](https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398/1 "2008-06-25T13:43:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![StYerk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@StYerk](https://www.ruby-forum.com/u/StYerk)\
**Post date:** [June 25, 2008, 1:46pm UTC](https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398/2 "2008-06-25T13:46:50Z")

</div>

On Jun 25, 12:27 pm, StYerk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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

> 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

---

<div class="post-metadata">

**Author:** ![StYerk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@StYerk](https://www.ruby-forum.com/u/StYerk)\
**Post date:** [June 25, 2008, 4:09pm UTC](https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398/3 "2008-06-25T16:09:03Z")

</div>

On 25 Jun 2008, at 14:57, StYerk wrote:

> 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

---

<div class="post-metadata">

**Author:** ![StYerk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f6c823/32.png) [@StYerk](https://www.ruby-forum.com/u/StYerk)\
**Post date:** [June 25, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/activerecord-classmethods-evaluate-condition-missing-in-rails-2-1-0/141398/4 "2008-06-25T15:58:26Z")

</div>

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
