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