views:

90

answers:

3

I want to do something like this:

validates_presence_of :name, :message => custom_message

def custom_message
  "Custom Message"
end

But when I try it I get "undefined local variable or method for custom method"

Whats up with that?

A: 

try this ,, if im not wrong

before_save :custom_message def custom_message self.custom_message = "Custom Message" if published == true end end

Kuya
hmmm not sure why I would want to do that... just wanna know why the validates method doesnt't see the local method
Cameron
A: 

Have you tried putting the definition of custom_message before the validates_presence_of line? validates_presence_of is a class method, and when it is evaluated Ruby has not yet seen the definition below it.

Yea tried that and no joy.
Cameron
+2  A: 

Think I figured it out. If you use a symbol instead of the method directly.

e.g :message => :custom_message

Cameron