Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:51:08+00:00 2026-06-10T06:51:08+00:00

I am new to ruby and have the following: students = Student.all(:order => score

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:51:09+00:00Added an answer on June 10, 2026 at 6:51 am

    The all method with arguments is a pre-Rails 3 API, and all(*args) is equivalent to find(:all, *args), which takes the :conditions option:

    students = Student.all(:conditions => "exam.date='01/01/2012'",
                           :order => "score DESC",
                           :limit => 5)
    

    It is generally preferred to use Rails 3’s chain-able relation methods, though:

    students = Student.where("exam.date='01/01/2012'").order('score DESC').limit(5)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
I have the following ruby code: class Mp def initialize Test.new.mytest Work.new.mywork ha address
I have the following test Ruby script: require 'tempfile' tempfile = Tempfile.new 'test' $stderr.reopen
I'm very new to Ruby on Rails, and have been getting the following error
Im new to ruby on rails and i have been following The Rails Space
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008
first of all, i am quite new to Ruby, although i have a strong
very new to Ruby, I've got the following situation. I have a file with
I am new to Rails & Ruby and have been following the http://ruby.railstutorial.org/ruby-on-rails-tutorial-book and
I'm pretty new to Ruby on Rails, forms lately have been giving me all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.