Ruby on Rails Friday, July 30, 2010

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 via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment