2013-10-24 97 views
1

我的會話控制器軌道4 NoMethodError在SessionsController#創建零未定義的方法`切片」:NilClass

 class SessionsController < ApplicationController 
     def create 
     user = User.from_omniauth(env["omniauth.auth"]) 

     session[:user_id] = user.id 
     redirect_to root_url 
     end 

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

我user.rb

 class User < ActiveRecord::Base 

     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 

末 誰能告訴我的事業錯誤我搜索SO相同但無法找到相關解決方案
結束

+0

你有什麼期待您'ENV [「omniauth.auth」]'變量持有... –

+0

您在'auth'上調用'#slice','auth'爲零。你的omniauth哈希值是零。 – depa

+0

我想要我的臉書認證 – Anish

回答

0

我解決了這個問題

self.from_omniauth嘗試創建新用戶,所以我得到了驗證錯誤電子郵件不能留空或用戶名不能留空,所以請評論您的驗證並嘗試。在模型

使用軌道模型場景「中的」 =>「創建」,「上」 =>「更新」,在您的驗證

相關問題