0

我的代码可以正常工作,循环浏览游标页面,直到 next_cursor == 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
4

1 回答 1

0
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
于 2013-09-04T09:47:46.553 回答