Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails, given an array of items, how to delete in the console

Given the following:

@users = User.where(:state => 1)

which 15 for: @users.length

In the rails console, is there a way to then delete all those records, perhaps by doing something like @users.delete?

like image 760
AnApprentice Avatar asked Apr 23 '11 00:04

AnApprentice


1 Answers

@users = User.where(:state => 1)

The simplest way is to use destroy_all or delete_all:

@users.destroy_all
# OR
@users.delete_all

That's all

like image 78
fl00r Avatar answered Oct 13 '22 01:10

fl00r