I am trying to find the sum of a column called length
, which is simple an integer column full of the number of seconds each record lasted for.
I have a search form setup to query the db for some conditions I have set in the controller:
@time_entries = TimeEntry.find(:all, :conditions => [ "(user_id = ?) AND (projecttitle LIKE ?) AND (date BETWEEN ? AND ?)", current_user, '%'+params[:projecttitle]+'%', @startdate, @enddate ])
and then I follow that query with my code that doesn't work, trying to sum the length
column of my returned query...
@total_time = @time_entries.sum(:length)
and then when I go to render this out in my view with <%= @total_time %>
, I get this error:
undefined method '+' for #<TimeEntry:0x007ffdbbd45b78>
Any ideas? Your help is very appretiated :)