[英]Invalid 'retry' Ruby (/rails)
I am trying to compare a current attribute with each attribute that is already in the database. 我正在尝试将当前属性与数据库中已经存在的每个属性进行比较。 If a certain condition is met, I want to break the loop, run a piece of code, and restart the loop.
如果满足特定条件,我想中断循环,运行一段代码,然后重新启动循环。
User.all.each do |user|
if user.name == obj_user.name
count += 1
retry
end
end
Although I don't see any cases to do it the way you are trying but still: 尽管我看不到有任何案例可以按照您尝试的方式进行,但是仍然:
User.each do |user|
begin
raise if user.name == obj_user.name
rescue
count += 1
retry
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.