Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何在rails中的活动记录上使用while和until循环?_Ruby On Rails - Fatal编程技术网

Ruby on rails 如何在rails中的活动记录上使用while和until循环?

Ruby on rails 如何在rails中的活动记录上使用while和until循环?,ruby-on-rails,Ruby On Rails,我有一个名为houses的模型,我需要一个房屋列表,比如“@houses=House.where(…)” 然后使用某种方法(不仅仅是一个简单的where)检查它们,直到得到匹配的记录(当该方法返回true时) 到目前为止,我只用过一次。如何使用“直到”或“WHILE”循环检查列表中的下一条记录 谢谢为什么不使用此功能 @houses = House.where(...) @house = @houses.detect { |h| your condition here } 如果使用Enumer

我有一个名为houses的模型,我需要一个房屋列表,比如“@houses=House.where(…)”

然后使用某种方法(不仅仅是一个简单的where)检查它们,直到得到匹配的记录(当该方法返回true时)

到目前为止,我只用过一次。如何使用“直到”或“WHILE”循环检查列表中的下一条记录

谢谢

为什么不使用此功能

@houses = House.where(...)
@house = @houses.detect { |h| your condition here }

如果使用
Enumerable
,则可以改用其方法,该方法从集合中返回块返回true的第一个对象for@yoavmatchulsky你说得对,我有点误解了这个问题。
@houses = House.where(...)
status = @houses.detect { |h| your condition here }.present?
return for you true/false