Ruby on Rails Calculations -


i'm new rails , coding in general, , i'm trying teach myself working on app delivery driver. have table called loads, , included columns gross weight, tare weight , net weight. way currently, driver have type in 3 weights manually. i'm trying figure out best way have app calculate net weight (by subtracting tare weight gross weight)and add net column. cut down on driver making simple math mistake. i'm using mysql, can point me in right direction?

i add before_validation callback model , let calculate missing value. this:

# in model before_validation :calculate_net_weight  private def calculate_net_weight   self.net_weight = gross_weight - tare_weight end 

btw. argue makes sense store 3 values in database if calculate 1 other two. having 3 values in databse might fix problems or might make calculation or statistics easier.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -