markmcdermott.io (js, ruby, ...etc) by mark mcdermott

Rails Console Delete Multiple

One-liner

08/31/2025

read time: 1 min

Today in Rails I wanted to find out if there was a one-liner that would delete multiple items by id in the Rails console. Turns out there is:

User.where(id: [1,2,3]).each(&:destroy)

The &: is apparently Ruby shorthand for passing a method as a block and the above expands to:

User.find([1,2,3]).each { |record| record.destroy }