Forum: Ruby on Rails sorting

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mohammad R. (Guest)
on 2006-04-16 05:31
I need to sort users by their rank how do I do this?
Ray B. (Guest)
on 2006-04-16 06:31
(Received via mailing list)
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
Mohammad R. (Guest)
on 2006-04-16 07:11
./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
Craig W. (Guest)
on 2006-04-16 07:23
(Received via mailing list)
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
Ray B. (Guest)
on 2006-04-16 07:32
(Received via mailing list)
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
Mohammad R. (Guest)
on 2006-04-16 08:25
@users = Users.find(:all, :order => "points DESC" )

It has to have DESC at the end
Ray B. (Guest)
on 2006-04-16 10:01
(Received via mailing list)
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
This topic is locked and can not be replied to.