Skip to content

Instantly share code, notes, and snippets.

@mileszs
Created June 16, 2010 19:11
Show Gist options
  • Select an option

  • Save mileszs/441127 to your computer and use it in GitHub Desktop.

Select an option

Save mileszs/441127 to your computer and use it in GitHub Desktop.
# I'll forget this again, so I'm saving it somewhere.
# I needed to remove duplicates from a table.
# Here's how I did it.
category_uniques = Category.all.index_by(&:name).values
Category.all.each { |cat| cat.destroy unless category_uniques.include?(cat) }
# Edit: Reduced to two lines, for fun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment