我正在尝试循环浏览控制台中的数组并使用 find_by_email 来定位用户:
a = [ "brian@labyrinth.com", "lmontoymail@gmail.com"]
a.each do |email|
u = User.find_by_email("#{a}")
u.delete
end
但我收到一个错误:
NameError: undefined local variable or method `email' for main:Object
在这里,我得到的答案是:
1.9.3p194 :035 > a = [ "brian@labyrinth.com", "lmontoymail@gmail.com"]
=> ["brian@labyrinth.com", "lmontoymail@gmail.com"]
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" = 'brian@labyrinth.com' ORDER BY users.created_at DESC LIMIT 1
NoMethodError: nil:NilClass 的未定义方法“销毁”