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.
3324a49b1605f0e2df7676ff64f5e712?d=identicon&s=25 Mohammad Ruby (mohammad)
on 2006-04-16 03:31
I need to sort users by their rank how do I do this?
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-16 04: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
3324a49b1605f0e2df7676ff64f5e712?d=identicon&s=25 Mohammad Ruby (mohammad)
on 2006-04-16 05: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
C1e5a9e9344b6d31b9df7303e6dc378a?d=identicon&s=25 Craig White (Guest)
on 2006-04-16 05: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
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-16 05:32
(Received via mailing list)
Craig White 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
3324a49b1605f0e2df7676ff64f5e712?d=identicon&s=25 Mohammad Ruby (mohammad)
on 2006-04-16 06:25
@users = Users.find(:all, :order => "points DESC" )

It has to have DESC at the end
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-16 08: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.