私は、CookieログインのためのRyan Bates氏の/ RailsCastチュートリアルに従い、構築中のアプリケーションで機能を思い出させます。Remind Me(エピソード274)のOmniAuth RailsCast(エピソード275)
[参考:http://railscasts.com/episodes/274-remember-me-reset-password?view=comments] 同じアプリケーションで彼のOmniAuth機能を紹介したかったのです。
[参考:http://railscasts.com/episodes/235-omniauth-part-1] 私はdeviseを使用していません。私は正しくTwitterアプリケーションページをロードしていますが、アプリケーションにリダイレクトするとエラーが発生します。 Twitter内でコールバックURLが正しく設定されています。
OmniAuthと私のauthentications_controllerでundefined method "authentications" for nil:NilClass
エラーが発生しました。具体的に私のコンソールは、読み取ります。ここ
NoMethodError (undefined method authentications for nil:NilClass):app/controllers/authentications_controller.rb:9:in create'.
は認証]コントローラーのコードです:ここで
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コードを維持しながら、私は受け付けており、エラーを回避することにより、自分のTwitterのアカウントでログインすることができますので、ツイッターで動作するようにOmniAuthを可能にしたいと思います。