Skip to content

Instantly share code, notes, and snippets.

@heo001997
heo001997 / revert_destroy_all.rb
Created September 23, 2021 16:24 — forked from 8parth/revert_destroy_all.rb
revert back accidently deleted Model.destroy_all in rails console
View revert_destroy_all.rb
Model.destroy_all
# if you haven't performed any other action after accidently deleting all records from Model,
# then _ would grab last response generated by Model.destroy_all
destroyed_records = _
destroyed_records.each do |destroyed_record|
Model.create(destroyed_record.attributes)
end