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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With