I have 3 tables: Projects, Tasks, Timeentries
Projects has_many tasks and has_many timeentries, :through => tasks
Tasks has_many timeentries.
In the Projects index, I would like to show a sum of all the timeentries for the project.
I’m trying to use:
<td><%= @project.tasks.timeentries.sum('time_entry') %></td>
But, I get undefined method `tasks’ for nil:NilClass
Any ideas?
Thanks
as Benjamin Udink ten Cate pointed out, most likely your instance variable is named @projects
if you are doing a traversing through projects like <%for project in @projects%> than you should be using project and not @project