mrg mrg - 1 year ago 67
Ruby Question

Retrive database records in Rails

My model named

contains 3 columns namely

Now how to get all the rows if the
gender = "male"
. I try to
fetch the data as shown below.

p = Person.find_by_gender("male")

The above statement properly worked. But it returns only 1 record. Because, the statement is converted to like following query.

SELECT "persons".* FROM "persons" WHERE "persons"."gender" = $1 LIMIT 1 [["gender", "male"]]

Due to limit is set to 1 it returns only 1 record. So, how to unset the limit? My requirement to get all the records in table if


Answer Source

use where

Person.where(gender: "male")

find method always returns only one record

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download