Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails validates_presence_of with multiple fields

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?

like image 552
Deimos620 Avatar asked Jan 04 '23 20:01

Deimos620


1 Answers

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.

like image 193
moyinho20 Avatar answered Jan 13 '23 10:01

moyinho20