how to handle error message when condition break both presence and numerical validation ?

20 views
Skip to first unread message

Fahim Patel

unread,
Jan 15, 2013, 11:41:18 PM1/15/13
to rubyonra...@googlegroups.com

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



 

Dheeraj Kumar

unread,
Jan 16, 2013, 12:04:42 AM1/16/13
to rubyonra...@googlegroups.com
1. Why do you have two presence validators?
2. add allow_blank: true to the numerical validator.

-- 
Dheeraj Kumar

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Bz2IOd8dFO8J.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Fahim Patel

unread,
Jan 16, 2013, 12:15:22 AM1/16/13
to rubyonra...@googlegroups.com
Thanks for reply
Let me try this, then i will reply you updated .

Fahim

Fahim Patel

unread,
Jan 16, 2013, 12:23:00 AM1/16/13
to rubyonra...@googlegroups.com
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.

Priya D.

unread,
Jan 16, 2013, 3:10:38 AM1/16/13
to rubyonra...@googlegroups.com
Try giving the following.

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

This validation will not be invoked if the age is not present.

--
Posted via http://www.ruby-forum.com/.

Fahim Patel

unread,
Jan 16, 2013, 3:49:18 AM1/16/13
to rubyonra...@googlegroups.com
Thanks
It works...

Best Regards
Fahim
Reply all
Reply to author
Forward
0 new messages