我正在尝试实现一个高清图,它总结了指定周的小时数。它目前正在做的是查看我的“努力”表并总结该表中的所有记录。但是,我想为当前用户计算特定周的小时数。我的highcharts.html.erb中有以下代码段。
series: [{
name: 'Hours',
data: [<% @efforts.each do |effort| %>
[Date.UTC(<%= effort.week_commencing.strftime("%Y,%m-1,%d") %>),<%= Effort.sum(:hours).
where(:week_commencing => week_commencing, :user_id => current_user.id)%>],<% end %>]
}]
});
});
我在pastebin http://pastebin.com/ifbQfR0i
上提供了完整的代码有解决方法吗?
更新:错误消息
Statistics#range
中的NameError显示/home/Project/app/views/statistics/range.html.erb行
115提出:
对于#&lt;#:0x9fdadc8&gt;未定义的局部变量或方法`week_commencing'提取的来源(第115行):
name: 'Hours', data: [<% @efforts.each do |effort| %> [Date.UTC(<%= effort.week_commencing.strftime("%Y,%m-1,%d")
%&gt;),&lt;%= Effort.sum(:小时)。 where(:week_commencing =&gt; week_commencing,:user_id =&gt; current_user.id)%&gt;],&lt;%end%&gt;] }]}); });
Efforts.rb
== Schema Information
Table name: efforts
id :integer(4) not null, primary key
project_task_id :integer(4)
user_id :integer(4)
week_commencing :date
hours :float
created_at :datetime
updated_at :datetime
答案 0 :(得分:1)
我不太确定,但不应该是:
%>),<%= Effort.sum(:hours). where(:week_commencing => effort.week_commencing, :user_id => current_user.id)%>],<% end %>] }] }); });
而不是
%>),<%= Effort.sum(:hours). where(:week_commencing => week_commencing, :user_id => current_user.id)%>],<% end %>] }] }); });