Reputation: 1809
This seems like a silly problem but I can't find the answer anywhere!
Is it possible to update_attributes()
and skip validations, like in save(validate: false)
?
I have a long form with some lengthy text
(not string
) fields, and I'd like to offer the user the ability to save their progress on the form. Normally, I want length minimums, etc, on the answers before they're able to submit it and move on, but in the case where they're just clicking "Save" I'd like to put whatever progress they've made in the database so they can come back and finish later. Is there a way to skip the validations in this case?
From looking around, it seems the only thing I can do is enumerate each field individually like so:
@obj.field1 = ...
@obj.field2 = ...
@obj.field3 = ...
...
@obj.save(:validate => false)
Is that really the case? I'd be worried about adding another field at some point in the future and forgetting to update the controller here.
Upvotes: 17
Views: 13560
Reputation: 83680
@obj.attributes = params[:obj]
@obj.save(false)
Update for Rails 3
@obj.attributes = params[:obj]
@obj.save(:validate => false)
Upvotes: 29