[英]Rails, helper not outputting results of a loop
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/ 我试图呈现一个表格,其中包含每周每天每小时的值,我实际上是使用这个jquery插件为图表着色,但是应该输出数据以匹配其网站上的数据: http:// www .geertdedeckere.be /店/ graphup /下载/ demo1的/
My data is being output by rails like this: 我的数据正由rails输出,如下所示:
@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..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? 所以主要的问题是在我的观点中我没有得到
content_tag
s我只得到hours
的值,所以html的输出字面上是0..23
,我如何通过我的帮助器获得所有这些td
的输出?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.