I have created a function in model that retrieves the idea of creating

it uisng this link:

http://stackoverflow.com/questions/1330273/how-to-calculate-difference-of-two-fields-on-form-submit-ruby-on-rails

The aim of the function is to calculate the following formula, provided

that all are fields in the table:

quantity_sold = receive + deliver

This is how my model looks like:

Class Iteminfo < ActiveRecord::Base

attr_accessor :receive, :deliver

before_create :calculate_quantity_sold

private

def calculate_quantity_sold

self.quantity_sold = receive.to_i + deliver.to_i

end

end

Now, when I enter values for the "deliver" and "receive" fields, say:

receive = 10

deliver = 10

I get the following value for "quantity_sold" ---> 20

Where is the problem?

The problem is that when I enter the values on the form for the

"receive" and "deliver" fields, and then hit the "Create" buttom, in the

"show" page, I get a "20" beside the "quantity_sold" field shown and

EMPTY fields for "deliver" and "receive".

The other problem is that when I for example want to see the data in my

table using Firefoxe's SQLite Manager I do NOT get any data shown

although I can see it in the form "index" page.

What is the problem here?

Thanks.