1

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?

4 Answers 4

3

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

e.g :message => :custom_message

Sign up to request clarification or add additional context in comments.

Comments

1

I got it working like this:

def self.custom_message
  "Custom Message"
end

validates_presence_of :name, message: custom_message

Comments

0

try this ,, if im not wrong

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

1 Comment

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

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.