Permalink
Browse files

Merge pull request #5 from bgentry/master

Player#display_name to avoid blank names
  • Loading branch information...
2 parents a2daa4c + 6a99683 commit 912ee52953c344745a821288e2f7a306e220f167 @mfine mfine committed May 1, 2012
Showing with 20 additions and 8 deletions.
  1. +3 −0 lib/ranked/player.rb
  2. +11 −3 lib/ranked/result.rb
  3. +3 −2 views/index.haml
  4. +1 −1 views/navbar.haml
  5. +2 −2 views/results.haml
View
3 lib/ranked/player.rb
@@ -1,4 +1,7 @@
module Ranked
class Player < Sequel::Model
+ def display_name
+ name || user
+ end
end
end
View
14 lib/ranked/result.rb
@@ -1,16 +1,24 @@
module Ranked
class Result < Sequel::Model
+ def loser
+ @loser ||= Player[loser_id]
+ end
+
+ def winner
+ @winner ||= Player[winner_id]
+ end
+
def winner_name
- Player[winner_id].name
+ winner.name
end
def loser_name
- Player[loser_id].name
+ loser.name
end
def opponent(player)
- [winner_name, loser_name].reject { |p| p == player.name }.first
+ [winner, loser].find { |p| p != player }.display_name
end
def result(player)
View
5 views/index.haml
@@ -6,9 +6,10 @@
%h4 Post result:
%form.form-inline{:method=>"post", :action=>"/results", :style=>"margin-bottom: 0;"}
%select{:name=>"winner_id"}
+ %option{:value=> nil}
- Ranked::Player.order(:user).all.each do |player|
- next if player == @user
- %option{:value=>player.id}= player.user
+ %option{:value=>player.id}= player.display_name
%input.btn.btn-primary{:type=>"submit", :value=>"Just beat me"}
@@ -22,4 +23,4 @@
%tr
%td= "##{i+1}"
%td
- %a{:href=>"/players/#{player.id}"}= player.name
+ %a{:href=>"/players/#{player.id}"}= player.display_name
View
2 views/navbar.haml
@@ -12,4 +12,4 @@
%a{:href => '/results'}Results
%ul.nav.pull-right
%li
- %a= @user.user
+ %a= @user.name || @user.user
View
4 views/results.haml
@@ -9,6 +9,6 @@
%tr
%td= result.at
%td
- %a{:href=>"/players/#{result.winner_id}"}= result.winner_name
+ %a{:href=>"/players/#{result.winner_id}"}= result.winner.display_name
%td
- %a{:href=>"/players/#{result.loser_id}"}= result.loser_name
+ %a{:href=>"/players/#{result.loser_id}"}= result.loser.display_name

0 comments on commit 912ee52

Please sign in to comment.