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 have been using this patten for seeds:
Category.find_or_initialize_by(id: category.id).update |c| c.name = category.name end
It works the same as Dale Wijnand's and Teoulas answers (only saves the instance once) but uses a block like in your question.