Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting Users with Rails Console

I want to delete some users and duplicate tags that are in my db. Is there a way I can use rails console to list all of these objects so I can pinpoint each one to delete them. They are not necessarily the last entries?

like image 334
ubique Avatar asked May 17 '11 17:05

ubique


1 Answers

Assuming your model is derived from ActiveRecord::Base and named User, you can do with rails console

pp User.all  # all users

or

pp User.all(:conditions => {:firstname => 'fred'}) # use hash conditions

or

pp User.all(:conditions => "lastname LIKE 'jenkin%'") # use custom sql conditions

and having the right user (say, id 42), you can do

User.delete(42)

That pp stands for pretty print. Another sometimes handy is y which prints stuff in Yaml format.

like image 97
EdvardM Avatar answered Oct 28 '22 00:10

EdvardM