Skip to content

Instantly share code, notes, and snippets.

@heo001997
Forked from 8parth/revert_destroy_all.rb
Created September 23, 2021 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heo001997/8fe14d40eecce1d8af4824fbfc047ef2 to your computer and use it in GitHub Desktop.
Save heo001997/8fe14d40eecce1d8af4824fbfc047ef2 to your computer and use it in GitHub Desktop.
revert back accidently deleted Model.destroy_all in rails console
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment