<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>nakaearth</author_name>
  <author_url>https://blog.hatena.ne.jp/nakaearth/</author_url>
  <blog_title>nakaearthの日記</blog_title>
  <blog_url>https://nakaearth.hatenadiary.org/</blog_url>
  <categories>
    <anon>rails</anon>
  </categories>
  <description>Rails3では、first_or_createというメソッドがありましたが、Rails4からはfind_or_create_byというメソッドを使います。 例として、次のように書きます。次の例はUserテーブルに対しemailで検索して、データがあればそれを返しなければ登録します。 User.find_or_create_by(email: auth:email]) do|user| user.name = auth[:name] user.email = auth[:email] end</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fnakaearth.hatenadiary.org%2Fentry%2F20140127%2F1390834686&quot; title=&quot;Rails4でデータあれば、それを返しなければ作る、という処理をやりたい時 - nakaearthの日記&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2014-01-27 23:58:06</published>
  <title>Rails4でデータあれば、それを返しなければ作る、という処理をやりたい時</title>
  <type>rich</type>
  <url>https://nakaearth.hatenadiary.org/entry/20140127/1390834686</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
