0
我遇到了麻煩下面的方法在我的用戶模型來處理哈希(「權威性」)我是從LinkedIn獲取用戶登入檢索數據稍後在我的用戶模型中調用'deep_get'方法,因爲我使用omniauth/linkedin gem創建了一個用戶。然而,它的返回了,我知道是不是零提供商/ UID /標題/電子郵件用戶字段零值。注射方法從哈希
我包括FIRST_NAME和姓氏領域作爲例子,因爲這種方法的工作(不返回零值),但(我知道)不良作風/異常處理。任何想法,爲什麼我的deep_get注入方法不工作來檢索散列中的數據,因爲我喜歡它?
def self.create_from_omniauth(auth)
create! do |user|
# i'd like to retrieve user information from linkedin per the following with my inject method, but i am getting nil values when i should be getting data.
# :provider and :uid are on the same branch level of data. first_name,last_name,email,etc. are on a branch just below called 'info'
user.provider = deep_get(auth, :provider)
user.uid = deep_get(auth, :uid)
user.headline = deep_get(auth, :info, :headline)
user.email = deep_get(auth, :info, :email)
# the below is working but i know pokemon exception handling is not good style.
begin
user.first_name = auth["info"]["first_name"]
rescue
end
begin
user.last_name = auth["info"]["last_name"]
rescue
end