# How to call a model object method for validation?

**URL:** <https://www.ruby-forum.com/t/how-to-call-a-model-object-method-for-validation/115707>\
**Category:** Rails\
**Created:** [September 27, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/how-to-call-a-model-object-method-for-validation/115707 "2007-09-27T20:24:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![datorrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cab0a1/32.png) [@datorrey](https://www.ruby-forum.com/u/datorrey)\
**Post date:** [September 27, 2007, 8:24pm UTC](https://www.ruby-forum.com/t/how-to-call-a-model-object-method-for-validation/115707/1 "2007-09-27T20:24:12Z")

</div>

This is the code I’m trying to get to work:

validates\_inclusion\_of :status,  
:in =\> poll\_statuses().keys

def poll\_statuses  
return {  
“closed” =\> “Closed”,  
“open” =\> “Open”  
}  
end

It says there’s no poll\_statuses method in Poll. How do I access this  
method? I’ve tried Poll.poll\_statuses().keys, I’ve tried defining the  
method above the validation. What am I missing here?

---

<div class="post-metadata">

**Author:** ![datorrey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cab0a1/32.png) [@datorrey](https://www.ruby-forum.com/u/datorrey)\
**Post date:** [September 27, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/how-to-call-a-model-object-method-for-validation/115707/2 "2007-09-27T23:00:52Z")

</div>

On 9/27/07, Daniel T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> }
> 
> ```
> 
> end
> 
> It says there’s no poll\_statuses method in Poll. How do I access this  
> method? I’ve tried Poll.poll\_statuses().keys, I’ve tried defining the  
> method above the validation. What am I missing here?

You’re correct about moving the method definition above the  
validation. That’s necessary.

The other problem is that you’ve defined poll\_statuses as an  
_instance_ method, but you’re calling it as a _class_ method. You need  
to define it as:

def self.poll\_statuses  
…
