2014-01-19 95 views
2

我正在嘗試將Facebook身份驗證集成到mongomapper的Rails應用程序中,並且出現以下方法的錯誤。我認爲錯誤是在first_or_initialize部分,因爲它是ActiveRecord查詢而不是mongomapper。用MongoMapper進行Facebook身份驗證

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 

編輯: Here is the terminal output when the error is thrown 有什麼建議?

回答

0

我在同一條船上。我能夠通過將first_or_initialize行更改爲此來創建用戶:

first_or_create(auth.slice(:provider, :uid)).tap do |user| 
+0

我最終找到了另一個解決方案,但我會在下次嘗試。謝謝! – emk411