我的代码工作正常,循环遍历游标页面,直到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
答案 0 :(得分: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