Skip to content

Instantly share code, notes, and snippets.

@8parth
Last active February 2, 2024 09:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 8parth/cb2a55c4f6a8b89b2afff6633e50a6c4 to your computer and use it in GitHub Desktop.
Save 8parth/cb2a55c4f6a8b89b2afff6633e50a6c4 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
@bonniesimon
Copy link

Wow. This was a lifesaver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment