Forum: Ruby on Rails How do I add data to record

Posted by crashbangboom (Guest)
on 2010-07-30 20:50
(Received via mailing list)
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...!
Posted by Robert Walker (robert4723)
on 2010-07-30 21:05
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
Posted by crashbangboom (Guest)
on 2010-07-30 21:21
(Received via mailing list)
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...!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.