First of all, thanks for you time. I have kind of a tricky question and
wanted to see what you guys thought.
Lets say I have this:
class Purchase < ActiveRecord::Base
validates_numericality_of :some_number, :only_integer => true
end
Then I do this:
purchase = Purchase.new
purchase.some_number = ‘This is not a number’
Right now the data is not correct. Is this ok? Why should I even let
invalid data like this get put into the some_number attribute? So my
question is this…
Is this better?
Instead of doing:
validates_numericality_of :some_number, :only_integer => true
Doesn’t it make more sense to validate the data as it’s being set and if
it’s not correct raise an exception? This way its not even possible to
get valid data into this attribute, which renders the statement
(validates_numericality_of :some_number, :only_integer => true)
unnecessary.
If you dig deeper I guess the real question is, will I ever use
purchase.some_number when its not pulled directly out of the db?
Any help is greatly appreciated.