I have class bill like below
class Bill < ActiveRecord::Base
#total = field in database
has_many :items
after_save :calculate_total
def calculate_total
total = self.items.map{|item| item.price}.sum
end
end
From the code above, the total will be auto calculated from on the
price on each items in this bill. However, user can try to assign the
value of this bill but when save the value with be replace with
after_save calculate_total.
The question is
Do we have a way to prevent user to directly assign the total value
but allow the calculate_total to assign the value?