Created
August 15, 2012 18:57
-
-
Save adamancini/3362557 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
attr_accessible :base_station_id, :data, :data_type, :device_id | |
validates :base_station_id, :presence => true | |
validates :device_id, :presence => true | |
validates :data_type, :presence => true | |
belongs_to :base_station | |
belongs_to :device | |
def method_missing(id, *args, &block) | |
if data.has_key?(id.to_s) | |
data.fetch(id.to_s) | |
else | |
super | |
end | |
end | |
# Want to generate the following sql: | |
# pass Date object as date to function | |
# SELECT COUNT(*) FROM `events` WHERE (`events`.`created_at` BETWEEN <day-1> AND <day+1>) | |
def self.total_events_by_day(date) | |
self.count(:all, :conditions => {:created_at => date-1..date+1}) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment