Çağdaş
Çağdaş

Reputation: 1023

Ordering|Sorting records with condition in RoR

I want to order my records with a condition. Lets say i have a Model. And fields are [x,y,z].

These are all string typed colums. I want to sort records by condition

z = "YGS-1" and y DESC

for example. So z has a condition if value is "YGS-1" and y with DESC condition. How can i sort|order my records. with these conditions.

Any idea?

Thanks.

Upvotes: 0

Views: 316

Answers (2)

Jon
Jon

Reputation: 10898

I'll assume your model is called Item:

@items = Item.where(:z => "YGS-1").order("y DESC")

Upvotes: 1

DGM
DGM

Reputation: 26979

Rails 3:

Model.where(:z => 'YGS-1').order('y DESC')

Upvotes: 1

Related Questions