title: Layer Supertype in ActiveRecord (Rails)
body: <p>I'm developing a ruby on rails app and I want to be able to excecute a method on every AR object before each save.</p>
  
  <p>I thought I'd create a layer-super-type like this:</p>
  
  <pre><code>MyObject &lt;&lt; DomainObject &lt;&lt; ActiveRecord::Base
  </code></pre>
  
  <p>and put in DomainObject a callback (before_save) with my special method (which basically strips all tags like "H1" from the string attributes of the object).</p>
  
  <p>The catch is that rails is asking for the domain_object table, which I obviously don't have.</p>
  
  <p>My second attempt was to monkeypatch active record, like this:</p>
  
  <pre><code>module ActiveRecord
    class Base
      def my_method .... end
    end
  end
  </code></pre>
  
  <p>And put that under the lib folder.</p>
  
  <p>This doesnt work, it tells me that my_method is undefined.</p>
  
  <p>Any ideas?</p>