Skip to content

Instantly share code, notes, and snippets.

@moustafasamir
Last active December 11, 2015 09:18
Show Gist options
  • Save moustafasamir/4579250 to your computer and use it in GitHub Desktop.
Save moustafasamir/4579250 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment