Reputation: 53
How do I update a record in rails by making it go through all the necessary validations? As far as i know
record.update_attributes(update_hash)
will skip all the validations. How do i update my record without skipping the validations? I'm using Rails 3.2 by the way.
Upvotes: 0
Views: 92
Reputation: 7033
In Rails 3.2, the method update_attributes
run all model validations, only the singular form update_attribute
skip validations. Fortunately, in Rails 4 they deprecated the later, in favour of update_column
(see commit).
Docs:
Upvotes: 1
Reputation: 829
update_attributes
itself checks for validations.
It returns false if unable to save (due to validation errors or an erroneous query).
Internally update_attributes
actually calls save
method itself which checks for validations before saving to the database.
Upvotes: 1