2012-08-28 2 views
2

내가 정확하게 this tutorial을 따라 만들 수 있지만이 오류가 점점 오전 :Omniauth-facebook 정의되지 않은 메서드 인 'slice'for nil : NilClass. NoMethodError SessionsController에서 #은

NoMethodError in SessionsController#create 
undefined method `slice' for nil:NilClass 
Rails.root: /Users/raybesiga/Documents/Sites/foodie 
Application Trace | Framework Trace | Full Trace 
app/models/user.rb:29:in from_omniauth' 
app/controllers/sessions_controller.rb:3:increate' 

은 그러나 내 user.rb 파일은 다음과 같습니다 : 다음과 같이

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :name, :email, :password, :password_confirmation, :remember_me,  :provider, :uid 
    validates_presence_of :name 
    validates_uniqueness_of :name, :email, :case_sensitive => false 
    # attr_accessible :title, :body 

    def self.from_omniauth(auth) 
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user| 
     user.provider = auth.provider 
     user.uid = auth.uid 
     user.name = auth.info.name 
     user.oauth_token = auth.credentials.token 
     user.oauth_expires_at = Time.at(auth.credentials.expires_at) 
     user.save! 
    end 
    end 
end 

sessions_controller.rb 파일은 다음과 같습니다

class SessionsController < ApplicationController 
     def create 
       user = User.from_omniauth(env["ominauth.auth"]) 
       # session[:user_id] = user.user_id 
       session[:user_id] = user.id 
       redirect_to root_url 
     end 

     def destroy 
       session[:user_id] = nil 
       redirect_to root_url 
     end 
end 

이 오류가 발생하는 이유는 무엇입니까?

답변

1

세션 컨트롤러에 env['omniauth.auth'] 철자가 잘못되었습니다. 너는 넣는다 env['ominauth.auth']

+0

고맙다 Charles !! 나는 그것을 어떻게 놓쳤는가? – raybesiga

+0

내 앱에서 두 번 철자를 잘못 입력했습니다. –

관련 문제