title: Extending ActiveRecord::Base
body: <p>I'm trying to add some custom methods to ActiveRecord. I want to add a <code>*_after</code> and <code>*_before</code> scopes for every <code>date</code> field of a model so I can do something like this:</p>
  
  <pre><code>User.created_at_after(DateTime.now - 3.days).created_at_before(DateTime.now)
  </code></pre>
  
  <p>I've followed the solution explained here <a href="https://stackoverflow.com/questions/2328984/rails-extending-activerecordbase/2330533#2330533">Rails extending ActiveRecord::Base</a> but when I execute the rails console and try to call the methods I get an <code>undefined method</code> error.</p>
  
  <p>Here's my code:</p>
  
  <pre><code># config/initializers/active_record_date_extension.rb
  require "active_record_date_extension"
  
  # lib/active_record_date_extension.rb
  module ActiveRecordDateExtension
    extend ActiveSupport::Concern
  
    included do |base|
      base.columns_hash.each do |column_name,column|
        if ["datetime","date"].include? column.type
          base.define_method("#{column_name}_after") do |date|
            where("#{column_name} &gt; ?", date)
          end
          base.define_method("#{column_name}_before") do |date|
            where("#{column_name} &lt; ?", date)
          end
        end
      end
    end
  end
  Rails.application.eager_load!
  
  ActiveRecord::Base.descendants.each do |model|
    model.send(:include, ActiveRecordDateExtension)
  end
  </code></pre>
  
  <p>What am I doing wrong?</p>