Saving Repeated Iterations to Database

I’m pretty new to Ruby on Rails.

I have multiple datapoints that I am saving in my database for a subject
called “quarterback”. All of those datapoints are added together to for
the value “xoi_qb”. This calculation is performed in my model:

def xoi_qb
sum=0
sum+= passing_yards|| 0
sum+= passing_yards|| 0
sum+= qb_rushing|| 0

Each value will change over time, and so the total of the sum, “xoi_qb”,
will change over time. Currently, the total for “xoi_qb” just updates
and the previous total is lost.

What I’d like to do is save each iteration of that total, every time
it’s changed. I don’t want to do a “cron job”, because I don’t want to
create a time-based schedule that performs a rake to see if any changes
were made…I just want that total for each “quarterback” value “xoi_qb”
to be saved to the database each time that I make a change.

That way, each “quarterback” will end up with many “xoi_qb” values that
go up and down in value. Right now, I just want to solve this and then
eventually I’d like to plot the datapoints in a chart (with Highcharts
or something similar). But for now, I just need to know how to save each
“xoi_qb” total with each change.

I have no idea how to do this.

Charles D. wrote in post #1173799:

I’m pretty new to rails.

you should use rails-forum :slight_smile:
https://www.ruby-forum.com/forum/rails

Sorry…I should have said Ruby on Rails. I’m new to both, but this is a
Ruby on Rails project. This is the correct forum for that right?

Regis d’Aubarede wrote in post #1173821:

Charles D. wrote in post #1173799:

I’m pretty new to rails.

you should use rails-forum :slight_smile:
Rails - Ruby-Forum