Adam
Adam

Reputation: 464

How to use "criteria" methods in Mongoid with Rails 3

I'd like to use the Mongoid criteria methods ( http://mongoid.org/docs/querying/criteria.html ). I have a model named College. In the College controller:

def index
  @colleges = College.all_of(:sat_rmw.gt => 1200, :in_state_tuition.lt => 12000)
end

This generates the error:

undefined method `all_of' for College:Class

Am I supposed to use criteria in the College Model as opposed to the Controller? Thanks in advance!

Upvotes: 0

Views: 1136

Answers (1)

theTRON
theTRON

Reputation: 9659

I was having this same problem too (might be a bug in the current version, but I can't find any tickets regarding it). Whatever the case, you can replicate this behaviour using the where and and methods instead. Your query above would become:

@colleges = College.where(:sat_rmw.gt => 1200).and(:in_state_tuition.lt => 12000)

Upvotes: 1

Related Questions