Ok, I want to start by saying I'm teaching myself Ruby on Rails and MySQL. I feel like I'm making some good progress, but I've come across an issue that I can't seem to figure out, and it seems to be an easy enough thing to do. Forgive me if this is silly, and maybe I'm not searching the right terms, but here's what I'm trying to do. I have a form for a truck driver to enter in his info from his haul ticket/Invoice. I can put in all the info from the ticket and get it saved to the database. The problem I'm having is, there is a field for the truck's empty weight and gross weight. I want the next field to auto populate with the difference of the gross and empty weights and save it to the Net Weight column of the database. Does this make sense? Can anyone just at least point me in the right direction?
Thanks for any help, and again pardon my newbie-ness....
-N8
Dépends on your mysql version but you can create a table with a generated column:
https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html
CREATE TABLE weights (
gross DOUBLE,
empty DOUBLE,
diff DOUBLE AS (gross - empty)
);