I am new to Rails and Ruby and am having a difficult time building the data needed for a Highchart. I am struggling with the syntax to map a pair of hashes to an array. Let me try and explain:
I have a table of "initiatives" which contains basically an ID and a Name. Then I have a table "trainings" that has the initiative_id field to map to the initiative table What I am trying to do is create a method that pulls the Initiative name and the count of records from the trainings, and returns an array with [[name,count],[name,count]] What I have been trying is this def training_count_by_initiative() initiative_name = Initiative.all.select("id,name") training_count = Training.group(:initiative_id).count initiative_name.map do |initiative| ??? This is the part I am struggling with end end I tried following Railscasts #223 but can't seem to get the mapping to work. I know it is just a Ruby syntax issue that I am not understanding so if someone can explain it to me I would greatly appreciate it. John -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/65059d263df02f69aaf20a16f1fdb664%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.