what if:
ranked_players = Array.new
Player.all(:order => 'intelligence').each_with_index do |player|
ranked_players << "#{index + 1}. #{player[:name]} with
#{player[:intelligence]} intelligence"
end
#now you have ranked players list
ranked_players.each do |player|
puts player
end
On Mon, Oct 10, 2011 at 11:33 PM, Pamela <[email protected]> wrote:
> I am making a browser-based game using ruby on rails and I am having
> trouble implementing a ranking system for my game. Each player has
> five skills: intelligence, creativity, strength, charisma and
> technological. I want the player to have a rank for each skill. The
> ranking I have in place right now gives the same rank if two players
> have the same amount of skill.
>
> SELECT COUNT(*) AS [rank] FROM players "+
> "WHERE intelligence >= "+
> "(SELECT intelligence FROM players WHERE id = #{@player.id})
>
> I want each player to have a different rank even if they have the same
> amount of skill as another player but I can't seem to figure out how
> to implement that. I have an intelligence column and an irank column,
> the same for the rest of the skills, and I was thinking that I could
> first sort the intelligence column and then according to that sorting
> assign a number to the irank column from 1 and so on but I can't
> figure out how to exactly implement this. I was thinking maybe a for
> loop or a .each do loop but I hit a roadblock. I know I can do
> Player.all(:order => 'intelligence DESC') to sort it but after that
> I'm stumped.
>
> I would appreciate any hints or help that anyone could provide me if
> willing. Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.