find_or_create_by
method but I didn’t know it had a very useful companion
create_with
.
@something ||= SomeModel.create_with(some: "stuff").find_or_create_by(foo: "bar")
This will either find a record
SomeModel.where(foo: "bar")
or create it with
SomeModel.create(foo: "bar", some: "stuff")
. Very useful.