{"version":"1.0","blog_title":"\u304b\u307f\u307d\u308f\u30fc\u308b","height":"190","html":"<iframe src=\"https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.kamipo.net%2Fentry%2F2020%2F12%2F16%2F190723\" title=\"create_or_find_by\u3067create\u3082find_by\u3082\u5931\u6557\u3055\u305b\u308b - \u304b\u307f\u307d\u308f\u30fc\u308b\" class=\"embed-card embed-blogcard\" scrolling=\"no\" frameborder=\"0\" style=\"display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;\"></iframe>","description":"Active Record\u306e\u8a71\u3067\u3059\u3002 create_or_find_by\u306e\u5b9f\u88c5\u306fcreate\u3057\u3066\u307f\u3066\u30e6\u30cb\u30fc\u30af\u5236\u7d04\u306b\u5f15\u3063\u304b\u304b\u3063\u305f\u3089find_by\u3057\u3066\u307f\u308b\u306a\u306e\u3067\u3001\u3075\u3064\u3046\u306b\u8003\u3048\u308b\u3068find_by\u306f\u6210\u529f\u3057\u305d\u3046\u306b\u898b\u3048\u307e\u3059\u3002 def create_or_find_by(attributes, &block) transaction(requires_new: true) { create(attributes, &block) } rescue ActiveRecord::RecordNotUnique find_by!(attributes) end \u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3059\u308b\u3068create_o\u2026","author_url":"https://blog.hatena.ne.jp/kamipo/","blog_url":"https://blog.kamipo.net/","image_url":null,"provider_name":"Hatena Blog","provider_url":"https://hatena.blog","width":"100%","type":"rich","published":"2020-12-16 19:07:23","author_name":"kamipo","categories":[],"title":"create_or_find_by\u3067create\u3082find_by\u3082\u5931\u6557\u3055\u305b\u308b","url":"https://blog.kamipo.net/entry/2020/12/16/190723"}