2013-01-15 92 views
0

社交登錄正在開發中,但一旦推到heroku,我得到NoMethodError (undefined method `each' for nil:NilClass)newDevise + Omniauth + Heroku在#new_with_session中的undefined方法

從我的用戶模型:

def self.new_with_session(params, session) 
    if session["devise.user_attributes"] 
    new(session["devise.user_attributes"], without_protection: true) do |user| 
     user.attributes = params 
     user.valid? 
    end 
    else 
    super 
    end 
end 

我已經達到了我的調試路障。有什麼想法嗎?調試想法?類似的體驗?

+0

你有一些變量爲零,當它不應該。每次通話在哪裏?但很可能你忘了配置你的生產環境;) –

回答

0

解決!問題實際上是與acts_as_taggable_on寶石。由於session["devise.user_attributes"]包含了所有User屬性,當它到達其中一個「acts_as_taggable」,就像在我的情況下爲「技能」或「興趣」時,它看起來像寶石魔術一樣變成多參數或嵌套參數屬性,然後軌試圖循環的值 - 這是我的情況。所以,如果"skills"=>nil存在,我得到一個undefined method each for nil錯誤。

我還沒有檢查出太多深度的寶石來源,但尚未確認問題出在哪裏,但我相信軌道中的錯誤來自https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb中的25行或27行。

簡單的解決方案是將session["devise.user_attributes"].delete_if { |k,v| v.blank? }添加到我的new_with_session方法。

def self.new_with_session(params, session) 
    if session["devise.user_attributes"] 
    session = session["devise.user_attributes"].delete_if { |k,v| v.blank? } 
    new(session, without_protection: true) do |user| 
     user.attributes = params 
     user.valid? 
    end 
    else 
    super 
    end 
end 
相關問題