Created
August 23, 2011 13:19
-
-
Save MarkBennett/1165079 to your computer and use it in GitHub Desktop.
Implementing ActiveRecord named scopes with a module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Item < ActiveRecord::Base | |
extend SpecialScopes | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SpecialScopes | |
def self.extended(base) | |
base.class_eval do | |
scope :paid, where(:paid => true) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code compiles and runs, but Item.paid doesn't exist and can't be used.