I want to take the sum of the all the columns earn that have the date today. I am trying to make a class method.
How to take the sum of all the columns earn where the column dato have the date today and display it in view?
My controller:
class ReklamersController < ApplicationController
layout 'reklamer'
def index
@reklamers = Reklamer.find(:all)
end
end
My model:
def self.total_on(date)
where("dato(date) = ?", date).sum(:earn)
end
My view:
<td><b><%= @reklamer.total_on(dato) %></b></td>
Index: Error: undefined local variable or method `dato'
Best regards,
A rails beginner
该类方法应该在您的模型中,而不是在控制器中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.