I have attributes with special validation where I use the message clause to display a special message just for that validation. Here is one example:
validat
I just walked through all this and found the rails guides for custom validators too hard-coded... I'm posting this here even though it's not exactly what you asked, but the Q title fits perfectly (which is why I read this post for my problem).
Custom validation with i18n message:
validate :something_custom?, if: :some_trigger_condition
def something_custom?
if some_error_condition
errors.add(:some_field_key, :some_custom_msg)
end
end
# en.yml
activerecord:
errors:
models:
some_model:
some_custom_msg: "This is i18n controlled. yay!"