Sha256: af9379cf19defa0e5fcc23d2a05674daf810226e18e40edb89c5767755386ccb
Contents?: true
Size: 865 Bytes
Versions: 1
Compression:
Stored size: 865 Bytes
Contents
class Total < ActiveRecord::Base belongs_to :totalable, :polymorphic => true belongs_to :user validates :totalable_type, :presence => true, :on => :create validates :totalable_id, :presence => true, :on => :create def self.json_data_for_chart(start_date,end_date) arr = [] start_date.beginning_of_day.to_date.upto(end_date.end_of_day.to_date) do |day| totals = self.where("created_at between ? and ?",day,day+1.day) arr << [day.to_time.to_i,totals.count] end arr end def self.json_labels_for_chart(start_date,end_date) totals = self.where("created_at between ? and ?",start_date.beginning_of_day,end_date.end_of_day) count = totals.count totals = totals.where(:totalable_id.not_eq => nil) label = totals.first.nil? ? "" : totals.first.totalable.to_total_chart_label [count,label] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
how_are_we_doing-0.0.4 | app/models/total.rb |