쿠키 로그인을 위해 Ryan Bates의/RailsCast 자습서를 읽고 필자가 작성중인 응용 프로그램의 기능을 생각 나게합니다.Remind Me (episode 274)와 OmniAuth RailsCast (에피소드 275) 문제
[참조 : http://railscasts.com/episodes/274-remember-me-reset-password?view=comments] 동일한 응용 프로그램에 대해 OmniAuth 기능을 소개하고자했습니다.
[참조 : http://railscasts.com/episodes/235-omniauth-part-1] 나는 장치를 사용하지 않는다. Twitter 응용 프로그램 페이지를 제대로로드하고 있습니다. 응용 프로그램으로 리디렉션 할 때 오류가 발생합니다. Twitter 내에서 콜백 URL을 올바르게 설정했습니다.
OmniAuth 및 my authentications_controller에서 undefined method "authentications" for nil:NilClass
오류가 발생합니다. 여기
NoMethodError (undefined method authentications for nil:NilClass):app/controllers/authentications_controller.rb:9:in create'.
을의 Authentications 컨트롤러 코드 : 특히 내 콘솔 읽기
여기class AuthenticationsController < ApplicationController
def index
authentications = Authentication.all
end
def create
auth = request.env["omniauth.auth"]
current_user.authentications.create(:provider => auth['provider'], :uid => auth['uid'])
flash[:notice] = "Authentication was successful."
redirect_to authentications_url
end
내 응용 프로그램 컨트롤러에서 CURRENT_USER 도우미 방법이다.
private
def current_user
@current_user ||= User.find_by_auth_token!(cookies[:auth_token]) if cookies[:auth_token]
end
helper_method :current_user
사용자는 많은 인증을 받았습니다. 인증은 사용자에게 속합니다.
나는 사용자가
도움말이 감사 내 CURRENT_USER 코드를 유지하면서 내가 수신하고 오류를 피함으로써 자신의 트위터 계정으로 로그인 할 수 있도록 트위터와 함께 작동하도록 OmniAuth 수 있도록하고 싶습니다.