Ruby on rails 直到循环无法在ruby中使用光标导航Twitter搜索结果

Ruby on rails 直到循环无法在ruby中使用光标导航Twitter搜索结果,ruby-on-rails,ruby,twitter,Ruby On Rails,Ruby,Twitter,我的代码可以工作,在游标页面中循环,直到下一个游标==0。。。但后来我在其他事情上遇到了一些问题,决定回到先前的承诺。现在我仍然使用相同的代码,但它不起作用。它将@cursor设置为next_cursor_str的值,但循环返回nil,并且只保存结果的第一页 class FollowersController < ApplicationController def create @cursor = "-1" until @cursor == "0" fol

我的代码可以工作,在游标页面中循环,直到下一个游标==0。。。但后来我在其他事情上遇到了一些问题,决定回到先前的承诺。现在我仍然使用相同的代码,但它不起作用。它将@cursor设置为next_cursor_str的值,但循环返回nil,并且只保存结果的第一页

class FollowersController < ApplicationController

  def create
    @cursor = "-1"
    until @cursor == "0"
      follower_info = current_user.twitter.followers(cursor: @cursor).attrs
      @cursor = follower_info[:next_cursor_str]

      follower_info[:users].each do |follower|
        current_user.followers.build(
          fid: follower[:id_str],
          name: follower[:screen_name]
        )
      end
    end
    current_user.save
    redirect_to action: 'static_pages#home'
  end

end
class FollowersController
如果更新显示了问题的解决方案,则不要将其添加为注释。相反,添加一个答案,并正确设置格式,使其可读。另外,提供足够的解释,以便其他人可以从中学习。我的跟随者模型验证fid的唯一性,因此当它试图构建一个已经存在的跟随者时,它返回零。通过设置“除非Follower.find_By(fid:Follower[:id_str]),我可以在尝试保存任何现有用户之前找到它们,从而防止返回nil。
follower_info[:users].each do |follower|
  unless Follower.find_by(fid: follower[:id_str])
    current_user.followers.build(
      fid: follower[:id_str],
      name: follower[:screen_name]
    )
  end
end