find_in_batches" NO BLOCK GIVEN(YIELD)" [英] find_in_batches "NO BLOCK GIVEN (YIELD)"

查看:89
本文介绍了find_in_batches" NO BLOCK GIVEN(YIELD)"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法可以获取模型和result_size.我试图用这种方法做的第一件事是:

I have a method where I take in a model and result_size . The first thing i try to do in this method is:

array = model.logs.find_in_batches(:batch_size => result_size)

但这是行不通的;相反,它返回无阻止给定(产量)".我想我只是不熟悉积木和收益率.如果有人可以帮助我理解/解决此问题,我将不胜感激!

But this doesn't work; instead it returns "No Block Given (Yield)". I guess I'm just unfamiliar with blocks and yields. If anyone could help me understand/fix this problem I would greatly appreciate it!

提前谢谢!

推荐答案

find_in_batches希望您将值传递到块中,如下所示:

find_in_batches expects you to pass the values into a block, as so:

model.logs.find_in_batches(:batch_size => result_size) do |models|
  models.each do |model|
    model.do_something
  end
end

这篇关于find_in_batches" NO BLOCK GIVEN(YIELD)"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆