In order to clean up some bad data I added a before save callback. Now I need to force all the models to be saved again. However no update operation happens if I do this
User.first.save
How do I force all the models to perform save operation even though I don't have any attributes changed.
You should be able to use touch
, it fires callbacks when it saves.
Alternatively turn off partial_updates: ActiveRecord::Base.partial_updates = false
As Josh Rickard commented to the accepted answer, since Rails 3.0.X touch
does not invoke validation and callbacks anymore.
You can, however, "touch" it manually with model.update_attribute(:updated_at,Time.now)
and skip validation and invoke callbacks that way.
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