I have multiple fields that should be validated with presence option.
I am trying to use validates_presence_of
instead of validates
.
Here is my code
validates_presence_of : first_name, last_name, birthday, sex,home, message: "This field shouldn't be blank"
But I want to show field name in the message. How can I show field name in message?
If you remove the message hash, and just use
validates_presence_of :first_name, :last_name, :birthday, :sex, :home
This will display a message containing all the field names that are blank when you are saving your object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With