# How do I add data to record

**URL:** <https://www.ruby-forum.com/t/how-do-i-add-data-to-record/192473>\
**Category:** Rails\
**Created:** [July 30, 2010, 8:50pm UTC](https://www.ruby-forum.com/t/how-do-i-add-data-to-record/192473 "2010-07-30T20:50:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![crashbangboom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@crashbangboom](https://www.ruby-forum.com/u/crashbangboom)\
**Post date:** [July 30, 2010, 8:50pm UTC](https://www.ruby-forum.com/t/how-do-i-add-data-to-record/192473/1 "2010-07-30T20:50:16Z")

</div>

I have a database table ‘tankticket’ that has the following fields:

id  
tank\_id  
ticket\_date  
batchid  
product  
api  
tank\_temp  
gauge  
gross\_vol  
vol\_correction  
roof\_correction  
net\_vol  
ticket\_vol  
created\_on  
updated\_on

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…!

Thanks in advance…!

---

<div class="post-metadata">

**Author:** ![crashbangboom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@crashbangboom](https://www.ruby-forum.com/u/crashbangboom)\
**Post date:** [July 30, 2010, 9:05pm UTC](https://www.ruby-forum.com/t/how-do-i-add-data-to-record/192473/2 "2010-07-30T21:05:16Z")

</div>

crashbangboom wrote:

> 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  
be tank\_tickets

> 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.

[http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Callbacks.html](http://railsapi.com/doc/rails-v2.3.8/classes/ActiveRecord/Callbacks.html)

---

<div class="post-metadata">

**Author:** ![crashbangboom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@crashbangboom](https://www.ruby-forum.com/u/crashbangboom)\
**Post date:** [July 30, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/how-do-i-add-data-to-record/192473/3 "2010-07-30T21:21:53Z")

</div>

yeah…my bad…the table name is ‘tanktickets’ and does follow rails  
naming conventions…!..So far, the entire application is running  
fine for all the simple things…now it’s on to the more complicated  
with the text in this help request…!

Thanks for the advice…I’m reading up on what you suggested now…!
