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 に答える