ruby - Showing Results from Nested Hash in Rails -


i've implemented linkedin api rails app.

the api returns data positions fields contains more fields details of last 2 positions. includes title, duration, description, etc...

how break down field data set job title of second job in rails app?

for example want the title of second position 1 links user.positions.title.1

the auth.extra.raw_info.positions.values contains following in database

[2, [#<omniauth::authhash company=#<omniauth::authhash id=165676 industry="marketing , advertising" name="reachlocal" size="1001-5000 employees" ticker="rloc" type="public company"> id=666166336 iscurrent=true startdate=#<omniauth::authhash month=2 year=2015> title="ux/ui designer">, #<omniauth::authhash company=#<omniauth::authhash id=1246381 industry="media production" name="freelance" size="myself only" type="self-employed"> id=561193709 iscurrent=true startdate=#<omniauth::authhash month=6 year=2014> summary="- defining business requirements determining success metrics, identifying target demographic, , understanding project objective/goals \n\n - conducting evidence-based user research through interviews , usability testing before , after redesign\n\n - delivering detailed information architecture, interaction , visual design specifications stakeholders\n\n - developing mental models through ux best practices\n\n - creating actionable , intuitive design flows\n\n - designing, building, , testing interactive prototypes iterate , evolve design concepts of project" title="ux designer">]] 

model

def self.from_omniauth(auth)   where(provider: auth.provider, uid: auth.uid).first_or_create |user|     user.provider = auth.provider     user.uid = auth.uid     user.email = auth.info.email     user.password = devise.friendly_token[0,20]     user.headline = auth.info.headline     user.first_name = auth.info.first_name     user.last_name = auth.info.last_name     user.industry = auth.info.industry     user.location = auth.info.location     user.summary = auth.extra.raw_info.summary     user.connections = auth.extra.raw_info.numconnections     user.linkedin_photo_url = auth.info.image     user.linkedin_url = auth.info.urls.public_profile     user.linkedin_position = auth.extra.raw_info.positions.values   end 

end

so, have array of length 2. second element, can use [1]; , .title title.

ie: auth.extra.raw_info.positions.values[1].title

note: indexes start zero; ie [0] first element, [1] second element, etc.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -