I have a model called shipments. I added some columns to the shipments table and there are some columns that are supposed to be calculated before save. So now I have to edit every record and hit update in order for the new columns to calculate and add the data.
So is there a way to perform a global save on all shipment records so the data can be added?
before_save :default_values
def default_values
self.volume = 1 unless self.volume
self.kilograms = 1 unless self.kilograms
self.status = "Open" if self.status.blank?
if self.mode == "Air"
self.estimated_transit_time = self.etd_origin + 7.days
self.eta_place_of_delivery = self.etd_origin + 7.days
else
self.estimated_transit_time = self.etd_origin + (Place.find_by_city(self.place_of_loading).transit_time).days
self.eta_place_of_delivery = self.etd_origin + (self.estimated_transit_time).days
end
end
You can make a method like this:
Then just call: