Is it possible to use standard validation methods in custom validation
methods?
eg:
def check_children
if children != ""
validates_numericality_of :children
end
end
When I run this code I get a no method error:
undefined method `validates_numericality_of' for #<Applicant:0x5d1bba4>
Is there any way around this?
Not really. validates_numericality_of is a class method that defines
an appropriate validation on a class. You may find the :allow_nil
and :if or :unless options useful
I created the field 'children' as a string (can't remember why, perhaps
because someone might enter 'none'??), so that doesn't work.
Is there any big advantage to changing the field 'children' into an
interger?
Well, if the column will hold numbers sure there is an advantage. You
can perform arithmetic and numeric comparisons. You can sort based on
the natural order of numbers, not based on lexicographical order.
Well, if the column will hold numbers sure there is an advantage. You
can perform arithmetic and numeric comparisons. You can sort based on
the natural order of numbers, not based on lexicographical order.
Yeah, that's true enough.
I'll get it changed as I want to do everything properly.
Thanks for your help.