I'm sorry. Of course `|player, index|` it's my misprint
On Wed, Oct 12, 2011 at 6:34 AM, Roy Situmorang wrote:

Correction:
ranked_players = Array.new
Player.all(:order => 'intelligence').each_with_index do |player, index|
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 Tue, Oct 11, 2011 at 8:49 PM, Kalastiuz wrote:

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 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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 7 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedOct 11, '11 at 10:52a
activeOct 14, '11 at 12:57p
posts7
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase