I have a database table ‘tankticket’ that has the following fields:
First thing I notice is that you’re not following the Rails default
naming conventions. If you have a class TankTicket the table name should
I Have a form that requires ‘tank_id’, ‘ticket_date’, ‘batchid’,
‘product’, ‘api’, ‘tank_temp’, and ‘gauge’
I’m calculating the rest of the data in the application helper. I need
to know where the calculations should be triggered and how to get the
input data and the calculated data to the database when the ‘create’
button is clicked…!
The application helper lives in the View layer of Model-View-Controller
(MVC). Data calculation belong in the Model layer. View layer helpers
like the application helper can be used for formatting of data for
display to the user, but should not directly calculate data that need to
be persisted into a data store.
Read up on ActiveRecord callbacks for information about where and when
to “trigger” your calculations. But, the first thing you need to do is
get your calculations out of the View helper and into the Model layer.
That might be the TankTicket class in your case, but I don’t have enough
information to know that for sure.