Rails Forms...Calculations and things

I have a partial form for tank tickets that requires end user
input…It is designed to minimize said input to reduce the
possibility for error…There are several other fields where
calculation results need to go before being sent to the database…!


  1. Is the ‘Create’ function the place to trigger the
  2. Where is the best practice location for the calcs…?..(model,
  3. How do I get the results into the database so they can be
    displayed later on…?

User input fields…

  1. A drop-down to select a tank number
  2. Drop-downs to select a date
  3. A Text field to input a ticket number
  4. A drop-down to select a product type
  5. A Text field to input an API gravity
  6. A Text field to input a tank temperature
  7. A Text field to input the tank gauge

The remaining five fields are calculated:
8) Gross Volume (each tank in the database has an ‘increment table’
used to determine the gross volume using the ‘gauge’)
9) Volume Correction Factor (calculated from the API gravity and the
tank temperature)
10) Roof Correction Factor (this is calculated using data from the
‘tanks’ table)
11) Net Volume (this is the result of multiplying the Gross Volume by
the Volume Correction Factor then adding the Roof Corr)
12) Ticket Volume (this is determined by comparing this ticket ‘Net
Volume’ to the last tickets ‘Net Volume’ for the same tank)

I have all the calculations running in rails and they are returning
the correct results…

So far, the only way I can get all this to work is to have the look-up
methods in the ‘public_helper’ and the raw calcs in the

Here’s an example of how I’m getting the ‘gross volume’:
def get_gross_vol( gauge )
@upperinc = Tank202increment.find(:first, :conditions => ["inc

= ?", gauge])
@lowerinc = Tank202increment.find(:first, :conditions => [“inc < ?”,
gauge], :order => ‘inc DESC’)
gross_vol = ((gauge - @lowerinc.inc) * 100 * @upperinc.multiplier) +
gross_vol = round(gross_vol, 2)
return gross_vol

Here’s a calculation example:

Calculate Density(kg/m3)


Observed API gravity

def get_density( api )
density = (141.5 / (131.5 + api.to_f) * 999.012)
density = round(density, 3)
return density

Thanks in advance for any light shed on this…I am new to Rails…am
luvin’ it and am trying to get it right…especially with regard to
‘Best Practices’/‘Standardization’…!