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.
Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database. Rails make it easy to add validations to your model classes and allows you to create your own validation methods as well.
@obj.attributes = params[:obj]
@obj.save(false)
Update for Rails 3
@obj.attributes = params[:obj]
@obj.save(:validate => false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With