Created
November 4, 2010 19:40
-
-
Save devn/663051 to your computer and use it in GitHub Desktop.
Rails 3 scope options to consider...
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
scope :latest_by_hashtag, lambda {|hashtag| { | |
:where => { :hashtags => hashtag }, | |
:order_by => :tweeted_at.desc, | |
:limit => 20 } | |
} | |
# OR # | |
def self.latest_by_hashtag hashtag | |
where(:hashtags => hashtag).order_by(:tweeted_at.desc).limit(20) | |
end | |
# OR # | |
module Scopes | |
def latest_by_hashtag hashtag | |
where(:hashtags => hashtag).order_by(:tweeted_at.desc).limit(20) | |
end | |
end | |
extend Scopes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment