moustafasamir
1/20/2013 - 3:03 PM

If you have an extension that should be shared by many associations, you can use a named extension module. For example:

If you have an extension that should be shared by many associations, you can use a named extension module. For example:

module FindRecentExtension
  def find_recent
    where("created_at > ?", 5.days.ago)
  end
end
 
class Customer < ActiveRecord::Base
  has_many :orders, :extend => FindRecentExtension
end
 
class Supplier < ActiveRecord::Base
  has_many :deliveries, :extend => FindRecentExtension
end