0

私はチュートリアルに従っています: http://railscasts.com/episodes/235-omniauth-part-1?autoplay=true

独自のサインインとサインアウトのプロセスが機能しています。しかし、Twitterのログインを認証しようとすると、

AuthenticationsController#create の NoMethodError

undefined method `authentications' for nil:NilClass

app/controllers/authentications_controller.rb:8:in `create'

私のルートは次のとおりです。

match '/auth/:provider/callback', to: 'authentications#create'

私の認証コントローラーでは、 create メソッドは次のとおりです。

def create
    auth =  request.env["omniauth.auth"]
    current_user.authentications.create(:provider => auth[:provider], :uid => auth[:uid])
    flash[:notice] = "Success"
    redirect_to authentications_url
  end

何が問題なのかわからない:/

あなたが私を助けることができれば、それは素晴らしいことです.

ありがとう。

4

1 に答える 1

0

私は問題を理解しました。システムにログインしていないため、current_user が null であるため、エラーが発生しました。

+

今、私はすべての経験を書き、Facebook と Twitter で複数の認証を提供するソース コードを使用してチュートリアルを作成しました 。 -考案/

于 2012-11-08T19:36:34.740 に答える