사용자 : 클래스에 대해 정의되지 않은 메소드 스캔을 수신합니다. 스캔 메소드 (라인 13 : 마지막 = resp.headers [ '링크'].레일즈 모델에서 "정의되지 않은 메소드"를 호출하지만 레일즈 콘솔에 의한 호출이 정확합니다.
class User
include Mongoid::Document
field :email
field :nickname
embeds_many :posts
def self.create_user(auth)
conn = FaradayStack.build 'https://api.example.com'
resp = conn.get "https://stackoverflow.com/users/#{auth.nickname}/list"
last = resp.headers['Link'].scan(/\d+/).last # <== error occurs here
n = 0
create! do |user|
user.email = auth["user_info"]["email"]
user.nickname = auth['user_info']['nickname']
while n <= last.to_i do
resp = conn.get "https://stackoverflow.com/users/#{auth.nickname}/list?page=#{n=n+1}"
resp.body.each do |repo|
user.posts.build(html_url: "#{repo['html_url']}",
description: "#{repo['description']}",
created_at: "#{repo['created_at']}",
pushed_at: "#{repo['pushed_at']}",
avatar_url: "#{repo['owner']['avatar_url']}")
end
end
end
end
end
내가 레일에 의해 동일한 코드를 호출 할 경우 콘솔이 잘 작동 : (/\d+/).last) 은 (클래스 메소드 self.create_user 내부 (인증)) 레일 사용자 모델이라고
ruby-1.9.2-p136 :158 > last = resp.headers['Link'].scan(/\d+/).last
=> "16"
ruby-1.9.2-p136 :159 > last = resp.headers['Link'].scan(/\d+/).last.to_i
=> 16
ruby-1.9.2-p136 :160 >
뭔가 상투적 인 것과 클래스 방법 개념에 관련된 것 같아요. 그러나 나는 그것을 고칠 수 없다.
UPDATE :
jimworm의 제안에, 나는 대신에 "잘못된"라인의 로거 레일을 넣어:
Rails.logger.info "\r\n" + "#{Time.now} " + "resp.headers['Link']: #{resp.headers['Link']}" + "\r\n"
내가 무엇을 얻을 것은 :
2011-09-30 16:40:03 +0200 resp.headers['Link']:
Redirected to http://localhost:3001/
Completed 302 Found in 3151ms
MONGODB blumb_dev['users'].find({:_id=>BSON::ObjectId('4e85d4c41d41c8103f000006')})
레일에있는 동안하면 콘솔 is :
ruby-1.9.2-p136 :181 > resp.headers['Link']
=> "<https://api.example.com/users/lgs/list?page=18>; rel=\"next\", <https://api.example.com/users/lgs/list?page=51>; rel=\"last\""
ruby-1.9.2-p136 :182 >
좋은 생각이야?
아마도'resp.headers [ 'Link']'는 당신이 생각하는 것과 다르지 않습니까? 'nil'또는 뭔가 ... 로그에서 로그 아웃하여 알아낼 수 있습니다. – jimworm
감사합니다. 업데이트를 참조하십시오 ... –
"오류"가 발생하면 HTTP 302가 발생하지만 "유효"한 것은 HTTP 200에서 발생한 것입니다. 이상하게 보입니다. –