Populating a column automatically based on the sum of other columns in the same row

I am new to Ruby on Rails and love what I see. I am also new to MySQL.

I am using a generic table with the ajax_scaffold. The table and
application are working great. However, I want to populate one column
for a new row based on the sum of other columns inputed by the user
when a new row is created.

The row represents a new user. Some of the columns for the user
represent test scores. One column is for a total score. How do I add
up the columns with scores and populate the total score column
dynamically?

Thanks,
Idmkid

You might want to look into Active Scaffold (http://www.activescaffold.com). It’s the successor to ajax scaffold, and it makes things like column totals really easy to do.

–Tyler

Simply use a AR Callback:

class User < Active_Record::Base
before_create :sum_scores

private
def sum_scores
  self.total_score = self.score1 + self.score2
end
end