How to DRY up this model a bit?

Hi again,

I have this model, trip.rb, which is getting bloated with the same things repeated all over. I'm new to both rails and ruby so I'm looking for help on how to DRY this thing a bit

I basically have to repeat this a lot of time (replacing "departure" and "departures" with other models) and I would love to find a way to write it once :slight_smile:

  def new_departure_attributes=(departure_attributes)     departure_attributes.each do |attributes|       departures.build(attributes)     end   end

  def existing_departure_attributes=(departure_attributes)     departures.reject(&:new_record?).each do |departure|       attributes = departure_attributes[departure.id.to_s]       if attributes         departure.attributes = attributes       else         departures.delete(departure)       end     end   end

  def save_departures     departures.each do |departure|       departure.save(false)     end   end

Can anyone educate me a bit? :slight_smile:

Thanks