I’m trying to give a custom validation message to a uniqueness validation. However, for the error message I need slightly complicated behavior, so I’m putting this logic in a private method (error_message_for_email_uniqueness).
Here’s the code I’m using
validates_uniqueness_of :email, message: error_message_for_email_uniqueness
Here’s the error I’m getting
/Users/dylandrop/.rvm/gems/ruby-1.9.2-p290/gems/attr_encrypted-1.2.0/lib/attr_encrypted.rb:229:in `method_missing': undefined local variable or method `error_message_for_email_uniqueness' for #<Class:0x00000103684198> (NameError)
I’ve tried using message: lambda { error_message_for_email_uniqueness }, which also doesn’t work. Also, I’ve tried wrapping it in a Proc instead of a lambda, which doesn’t get me anywhere.
How can I get around this?
Did you define error_message_for_email_uniqueness as a class method?
I did a quick test, and this works fine: