I am trying to implement a highchart that sums hours for a specified week. What it is currently doing is looking at my ‘efforts’ table and summing all records in that table. However I am trying to sum hours for a particular week, for the current user. I have the following snippet from my 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 %>]
}]
});
});
I have the full code available on pastebin http://pastebin.com/ifbQfR0i
Is there a way around this?
Updated: Error message
NameError in Statistics#range
Showing /home/Project/app/views/statistics/range.html.erb where line
115 raised:
undefined local variable or method `week_commencing’ for #<#:0x9fdadc8> Extracted source (around line #115):
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 %>]
}] }); });
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
I’m not quite sure, but shouldn’t it be:
instead of