How to call a model object method for validation?

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?

On 9/27/07, Daniel T. [email protected] 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