<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>masaru_furuya</author_name>
  <author_url>https://blog.hatena.ne.jp/masaru_furuya/</author_url>
  <blog_title>1日1%成長するブログ</blog_title>
  <blog_url>https://masarufuruya.hatenadiary.jp/</blog_url>
  <categories>
    <anon>Rails</anon>
    <anon>実装</anon>
    <anon>ActiveRecord</anon>
  </categories>
  <description>before_xxx, after_xxxといったActiveRecordのコールバックを特定の条件で絞り込みしたい時は、 ifオプションを使うのが楽。 after_update :update_fuga, if: -&gt; { saved_change_to_hoge_column? } ただこれだとコールバックに引数を指定したい時に上手くいかない。 そういった場合は以下のようにラムダ式の中で自分でrubyのコードを書いてしまえばいい。 after_update -&gt; { update_fuga(&quot;fuga&quot;) if saved_change_to_hoge_column? } 便利。</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fmasarufuruya.hatenadiary.jp%2Fentry%2F2020%2F05%2F08%2F094641&quot; title=&quot;Railsのコールバックをifで絞りつつ引数を指定する方法 - 1日1%成長するブログ&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>2020-05-08 09:46:41</published>
  <title>Railsのコールバックをifで絞りつつ引数を指定する方法</title>
  <type>rich</type>
  <url>https://masarufuruya.hatenadiary.jp/entry/2020/05/08/094641</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
