I am new to ruby and have the following:
students = Student.all(:order => "score DESC",
:limit => 5)
However I want to put a where clause into this as well but I get the error “Unknown key: where”. My student table references an exam table (t.references :exam) which has a date field so I need to do something like:
students = Student.all(:where => "exam.date='01/01/2012'",
:order => "score DESC",
:limit => 5)
How do I use a where clause in the all method and is exam.date='01/01/2012' correct ?
The
allmethod with arguments is a pre-Rails 3 API, andall(*args)is equivalent tofind(:all, *args), which takes the:conditionsoption:It is generally preferred to use Rails 3’s chain-able relation methods, though: