I\'m looking for a clean way to create a record with a set of attributes if the record does not exist and - if the record do exist - to update its attributes. I love the syn
I liked fl00r's answer. But why do we have to save the object every time? We can check if its already there in records or else save it
def self.find_or_create_by_id(id, &block) obj = self.find_by_id(id) unless obj obj = self.create(id: id) end obj end