Add heartbeat model, next_heartbeat_time and update_heartbeat_time on device registration

This commit is contained in:
leenasn
2015-11-09 13:43:21 +05:30
parent 185b10d8e7
commit 0e8b403142
11 changed files with 89 additions and 4 deletions

14
app/models/heartbeat.rb Normal file
View File

@@ -0,0 +1,14 @@
class Heartbeat < ActiveRecord::Base
belongs_to :device, counter_cache: :heartbeats_count
after_create :update_device_latest_heartbeat_recd_time
def update_device_latest_heartbeat_recd_time
self.device.last_heartbeat_recd_time = self.created_at
self.device.save
end
def next_heartbeat_time
device.next_heartbeat_time
end
end