I have a user model and bid model. I want the user to know that the score stored in their rank method Based on "i.e.", "i.e.", "i.e.", "i.e.", i.e. " user.ccore method based on" 3/7 ". Currently, I use the geek_rank method in the bid model Trying to hit:
def user_rank (my_id) # Find all bids associated with parent traffic object bids = bid.fund_b_ticket_id (self. Ticket.Id) bids = BidsArt_b {| B | B.user.score} i = 0b in B + i = = b.user_id.to_i == my_id.to_i myrank = i end-end user_rank = myrank.to_s + " / "+ I.to_s end The ordering method works for some reason, but when I try to sort the model, can anyone tell me how the problem How is my code worthless? :)
To clarify:
The actual error I get is missing an error.
Method find_by_ticket_id array does not return; It gives a bid instead use find_all_by_ticket_id
bids = bid.fund_all_byte_ticket_id (self.ticket.id) bids = bids.sort_by {| B B.user.score} I would like to rewrite your method:
def user_rank (my_id) # Find the bid by given ID score = Bid.find_b_id (my_id) .user.score # ticket calculation = bid Get the total number of bids for the quote ((terms => {ticket_id => self.ticket.id}) # Rank rank = Bid.count (: conditions => ["ticket_id =? And users .score & gt ;? ", Self.ticket.id, score],: joins = & gt;: user) + 1" # {rank} / # {Most calculations are done by DB in this approach. Alert 1 > This method will return the same rank for people with similar scores.
Example:
#name #score #rank foo 5 4 times 6 2 Kate 6 2 Kevin 8 1
Warning 2
This Solution your equal Performance measures are better than that. But to calculate this rank N * 3 rounds are required on the server.
Comments
Post a Comment