开发者

Deleting Users with Rails Console

开发者 https://www.devze.com 2023-03-06 08:29 出处:网络
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 eac开发者_JAVA技巧h one to delete them. They are

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 eac开发者_JAVA技巧h one to delete them. They are not necessarily the last entries?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消