Forum: Ruby on Rails how to handle error message when condition break both presence and numerical validation ?

Posted by fahim patel (fahim_patel)
on 2013-01-16 05:42
(Received via mailing list)
Hi all,

I have one numeric field "age" and it have two validation presence and
numerical true.
When i click submit without filling any value then i face error message 
is
"is not number" ,but error message should be "is should be presence". 
How
to set this message?
Both the condition are satisfying.

Did i have to configure en.yml ?

Thanks

Fahim
Posted by Dheeraj Kumar (Guest)
on 2013-01-16 06:05
(Received via mailing list)
1. Why do you have two presence validators?
2. add allow_blank: true to the numerical validator.


--
Dheeraj Kumar
Posted by fahim patel (fahim_patel)
on 2013-01-16 06:16
(Received via mailing list)
Thanks for reply
Let me try this, then i will reply you updated .

Fahim
Posted by fahim patel (fahim_patel)
on 2013-01-16 06:24
(Received via mailing list)
No, your not getting my question , actually i want presence and numeric
validation on "Age" field.
When i click submit without filling any value then i face error message 
is
"is not number" ,but error message should be "is should be presence". 
How
to set this message?

Hope you understood issue.
Posted by Priya D. (priya_d)
on 2013-01-16 09:10
Try giving the following.

validates :age, :numericality => true, :allow_nil => true

This validation will not be invoked if the age is not present.
Posted by fahim patel (fahim_patel)
on 2013-01-16 09:50
(Received via mailing list)
Thanks
It works...

Best Regards
Fahim

On Wednesday, January 16, 2013 1:40:38 PM UTC+5:30, Ruby-Forum.com User
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.