Skip to content

Instantly share code, notes, and snippets.

@devn
Created November 4, 2010 19:40
Show Gist options
  • Save devn/663051 to your computer and use it in GitHub Desktop.
Save devn/663051 to your computer and use it in GitHub Desktop.
Rails 3 scope options to consider...
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