Skip to content

Instantly share code, notes, and snippets.

@listrophy
Forked from devn/rails_3_scope_options.rb
Created November 4, 2010 19:57
Show Gist options
  • Save listrophy/663081 to your computer and use it in GitHub Desktop.
Save listrophy/663081 to your computer and use it in GitHub Desktop.
scope :latest_by_hashtag, lambda {|hashtag| {
:where => { :hashtags => hashtag },
:order_by => :tweeted_at.desc,
:limit => 20 }
}
# OR #
module MyModelModules
module Scopes
extend ActiveSupport::Concern
included do
scope :latest_by_hashtag, lambda {|hashtag| {
:where => { :hashtags => hashtag },
:order_by => :tweeted_at.desc,
:limit => 20 }
}
end
end
end
class MyModel
include Mongoid::Document
include MyModelModules::Scopes
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment