Hey Everyone
I’m not sure how to ask this properly - that’s probably the reason I’m
not sure how to implement it. I’m an intermediate noob and I’m not
sure how to bring this together…
Here’s my scenerio…
people using my system record “readings” every month to determine
month to month usage. Here’s the calculation…
{ This months reading} - {last months reading} = the usage for this
month
When adding a new reading record I want the system to look at the two
readings, calculate the usage, and then insert it possibly using an
“after_save” function to store the usage. Here’s the basic idea, but
I’m not sure how to implement it - any ideas or suggestions would be
helpful. This seems to be something I would want to handle in my
model, but then I’m not sure how I call it when I save the record.
def get_usage(id,lastmonth,reading)
@last_month=Readings.find(:all, :conditions=[:month =>
lastmonth, :id=>id])
current_usage =reading-@last_month.reading
return current_usage
end
Any help is appreciated.
Thanks
Chris