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