# Sorting

**URL:** <https://www.ruby-forum.com/t/sorting/93952>\
**Category:** Rails\
**Created:** [April 16, 2006, 3:31am UTC](https://www.ruby-forum.com/t/sorting/93952 "2006-04-16T03:31:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 3:31am UTC](https://www.ruby-forum.com/t/sorting/93952/1 "2006-04-16T03:31:15Z")

</div>

I need to sort users by their rank how do I do this?

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 4:31am UTC](https://www.ruby-forum.com/t/sorting/93952/2 "2006-04-16T04:31:39Z")

</div>

Mohammad Surname? wrote:

> I need to sort users by their rank how do I do this?

Assuming a User model with a comparable rank attribute,

@users = User.find(:all :order =\> “rank” )

–

Ray

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 5:11am UTC](https://www.ruby-forum.com/t/sorting/93952/3 "2006-04-16T05:11:41Z")

</div>

./script/…/config/…/app/controllers/users\_controller.rb:12: parse  
error, unexpected ‘:’, expecting ‘)’  
@users = Users.find(:all :order =\> “points” )  
^  
./script/…/config/…/app/controllers/users\_controller.rb:12: parse  
error, unexpected ‘)’, expecting kEND  
./script/…/config/…/app/controllers/users\_controller.rb:51: parse  
error, unexpected $, expecting kEND

this is the error I got when I ran it

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 5:23am UTC](https://www.ruby-forum.com/t/sorting/93952/4 "2006-04-16T05:23:21Z")

</div>

On Sun, 2006-04-16 at 05:11 +0200, Mohammad Surname? wrote:

> ./script/…/config/…/app/controllers/users\_controller.rb:12: parse  
> error, unexpected ‘:’, expecting ‘)’  
> @users = Users.find(:all :order =\> “points” )  
> ^  
> ./script/…/config/…/app/controllers/users\_controller.rb:12: parse  
> error, unexpected ‘)’, expecting kEND  
> ./script/…/config/…/app/controllers/users\_controller.rb:51: parse  
> error, unexpected $, expecting kEND
> 
> this is the error I got when I ran it

* * *

I would think that you would need a comma between :all and :order…

@users = Users.find(:all, :order =\> “points” )

Craig

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 6:25am UTC](https://www.ruby-forum.com/t/sorting/93952/5 "2006-04-16T06:25:55Z")

</div>

@users = Users.find(:all, :order =\> “points DESC” )

It has to have DESC at the end

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 5:32am UTC](https://www.ruby-forum.com/t/sorting/93952/6 "2006-04-16T05:32:24Z")

</div>

Craig W. wrote:

> > this is the error I got when I ran it
> 
> * * *
> 
> I would think that you would need a comma between :all and :order…
> 
> @users = Users.find(:all, :order =\> “points” )

True.

–

Ray

---

<div class="post-metadata">

**Author:** ![mohammad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mohammad](https://www.ruby-forum.com/u/mohammad)\
**Post date:** [April 16, 2006, 8:01am UTC](https://www.ruby-forum.com/t/sorting/93952/7 "2006-04-16T08:01:19Z")

</div>

Mohammad Surname? wrote:

> @users = Users.find(:all, :order =\> “points DESC” )
> 
> It has to have DESC at the end

Also true, but only if the largest values are the highest rank.

That part of your question was unspecified.

–

Ray
