Suggested validation parameter of:
validates_numericality_of :price, :only_integer => true
conflicts with the migration add_test_data obj.create method setting
:price => 28.56
You might need to update your beta book, because I can’t find any
reference to :only_integer on that page. I’m looking at version B1.16.
No error is produced in log/development.log that indicates why the test
data is not being entered btw.
Accurate error output would have vastly decreased the time it took me
to locate this problem as a rails/ruby newbie.
Ah, but think how much you’ve learned in figuring out this problem by
Seriously, though, validation failures aren’t reported as errors in the
log because they aren’t errors. It’s a part of the normal application
flow: someone fills out a form incorrectly, the validation fails, and
you redisplay the form. For this reason, the common methods (.save,
.create) don’t raise an exception if the record could not be saved due
to validation failures.
If it makes sense in your application, you can use the alternative
forms .save! and .create!, which will raise an exception if the
So in this migration, yes, it might have been better to write the
Product.create() lines so that an exception is raised if the creation
of the test data failed. That way you would have been alerted to the
problem. But I don’t think it’s a fundamental problem with Rails.