If i have a booking, with a method total, which calculates the total price of the booking from the sum of all the prices of activities that belong to appointments, where a booking hasmany appointments the following seems to give the right answer, but it seems horrid. How can I improve this?
def total
# TODO shouldn't this be a db query?
total = 0
self.appointments.each do |appointment|
unless appointment.activity.price.nil?
total += appointment.activity.price.to_f
end
end
total
end
nilhandling. – Quentin Pradet Feb 27 at 7:21