i am seeking some general info about how to get at a certain value and
how to get that value in a method.
for example, lets say i have a machine.
each machine has_many :sensors
so sensor belongs_to :machine
sensor also has_many :reports
each report has a duration field that is then number of seconds since
the last report of a certain value
now if i wanted to add the seconds together for a total when in a
certain status, i would do something like this.
total = 0
for row in results
duration = row
value = row
if value == ‘on’:
total += duration
of course in rails we have sensor.value, sensor.duration
so, anyway. i want to list in a table these figures.
so i need a method in sensor.rb to do this, right
so if i have for machine in machines do
<%= machine.sensor.total %>
how do i declare that ?
in the Sensor class, do i have
i dont know what to put here to get the right sensor
and is it def total, or is it def self.total ?
so for sensor in machine.sensors |sensor| do