I trying to render a table which values for each hour of everyday of the week, I'm actually using this jquery plugin to color the chart, but the data should be output to match the one on their site here: http://www.geertdedeckere.be/shop/graphup/download/demo1/
My data is being output by rails like this:
@data = [
{"day"=>1.0, "hour"=>19.0, "count"=>6623.0},
{"day"=>1.0, "hour"=>20.0, "count"=>7242.0},
{"day"=>1.0, "hour"=>21.0, "count"=>7148.0},
{"day"=>1.0, "hour"=>22.0, "count"=>7196.0},
{"day"=>1.0, "hour"=>23.0, "count"=>7244.0},
{"day"=>2.0, "hour"=>0.0, "count"=>7147.0},
{"day"=>2.0, "hour"=>1.0, "count"=>7217.0}
# ...
]
And my helper looks like the following, and this is where the problem lies
def table_counts(data)
days = 1..开发者_Python百科7
hours = 0..23
hours.each do |hour|
content_tag(:td, hour)
day_of_week = data.select {|f| f["hour"] == hour }
day_of_week.each do |d|
content_tag(:td, d['count'])
end
end
end
So the major issue is in my views I don't get the content_tag
s I just get the value of hours
, so the output to the html is literally 0..23
, How can I have all those td
s output via my helper?
each
returns the collection iterated over. You want map
. map
returns an array that you will then want to join
.
精彩评论