user107680
user107680

Reputation: 81

Find a Portion of a Database in Ruby

Say for example I have the following database of instances of a class called Obj:

| id | attr1 |
+----+-------+
| 10 |   A   |
| 15 |   B   |
| 20 |   C   |
| 50 |   D   |

Now let's say I want to find all of the instances of Obj with id greater than 10. How would I do that?

I want to write Obj.where(id > 10).all. What is the proper way to accomplish this?

All help is appreciated. Thanks!

Upvotes: 0

Views: 31

Answers (2)

pangpang
pangpang

Reputation: 8821

Have a try:

Obj.where("id > ?", 10)

you will find different ways to retrieve data from the database using Active Record from rails guide.

Upvotes: 1

djaszczurowski
djaszczurowski

Reputation: 4523

try

Obj.where("id > ?", 10) 

Upvotes: 0

Related Questions