Monday, 15 June 2015

ruby on rails - Active Record syntax issues and looping in the hash -



ruby on rails - Active Record syntax issues and looping in the hash -

i have hash this:

population_summaries = { 'aco' => [ # year , member_count [2013, 523031], [2012, 492349], [2011, 432573] ] }

where "aco" illustration name of organization organization table. , want insert construction of hash within populationsummary table illustration hash above in populationsummary table:

aco, 2013, 523031 aco, 2012, 492349 aco, 2011, 432573 org_name, year, member_count

i new activerecord methods , ruby methods working hash,array, etc.. how far got, looks have syntax errors , not sure if code looks , work or not. if take , see mistakes in next code:

population_summaries.each |org_name, summaries| org_id = organization.find_or_create_by_name(org_name).id summaries.each |year, member_count| populationsummary.create ( :organization_id => org_id, :year => year, :member_count => member_count ) end end

edit: code many error, of them illustration are:

syntax error, unexpected tassoc, expecting ')' :organization_id => org_id,

syntax error, unexpected tassoc, expecting tcolon2 or '[' or '.' :year => year,

syntax error, unexpected tassoc, expecting tcolon2 or '[' or '.' :member_count => member_count ^

ruby-on-rails ruby

No comments:

Post a Comment