find_in_batches “NO BLOCK GIVEN (YIELD)”

感情迁移 提交于 2019-12-11 07:33:00

问题


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!

Thanks in advance!


回答1:


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


来源:https://stackoverflow.com/questions/5153512/find-in-batches-no-block-given-yield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!