Created
December 14, 2010 14:16
-
-
Save pjb3/740476 to your computer and use it in GitHub Desktop.
Fixes ActiveRecord's named_scope API. Place this into config/initializers/def_scope.rb
This file contains hidden or 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
| # Having to use a lambda when defining a scope is ugly and stupid | |
| # I've never had a use case for a scope extension | |
| # This allows us to just use a block | |
| module DefScope | |
| def def_scope(name, &blk) | |
| scope name, blk | |
| end | |
| end | |
| ActiveRecord::Base.extend DefScope | |
| # Usage example: | |
| # | |
| # class Person < ActiveRecord::Base | |
| # def_scope :active_as_of do |date| | |
| # { :conditions => ["active_at > ?", date] } | |
| # end | |
| # end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment