I'm trying to cycle through an array in console and use find_by_email to locate the User:
a = [ "[email protected]", "[email protected]"]
a.each do |email|
u = User.find_by_email("#{a}")
u.delete
end
But I'm getting an error:
NameError: undefined local variable or method `email' for main:Object
Here, what I get based on the answer:
1.9.3p194 :035 > a = [ "[email protected]", "[email protected]"]
=> ["[email protected]", "[email protected]"]
1.9.3p194 :036 > a.each do |email|
1.9.3p194 :037 > u = User.find_by_email(email)
1.9.3p194 :038?> u.destroy
1.9.3p194 :039?> end
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."email" = '[email protected]' ORDER BY users.created_at DESC LIMIT 1
NoMethodError: undefined method `destroy' for nil:NilClass