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 did this yesterday, wishing there was a way to do it in a one-liner.
Ended up going with (using your code):
c = Category.find_or_initialize_by_id(category.id)
c.name = category.name
c.save
Perhaps there is a nicer way, but this is what I used.
[Edit: use initialize instead of create to avoid hitting the DB twice)