开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜