Permalink
Browse files

added a sort by position and alphabetize feature

  • Loading branch information...
1 parent 65b4235 commit 05bc01ff4791cd270c57f737d251dd5520228960 James Trowbridge committed May 6, 2010
@@ -12,6 +12,7 @@ def index
def show
@pick = Pick.find(params[:id])
+ @players = Player.undrafted
end
def new
@@ -59,7 +60,7 @@ def draft_player
draft_over = Pick.current.team.draft(player)
respond_to do |format|
- unless draft_over && !player.save
+ if (!draft_over && player.save)
flash[:notice] = 'Player was successfully drafted.'
format.html { redirect_to(pick_path(Pick.current)) }
else
@@ -43,6 +43,10 @@ def destroy
end
def undrafted
- @players = Player.undrafted
+ unless params[:position.nil?]
+ @players = Player.filter_position(params[:position])
+ else
+ @players = Player.undrafted
+ end
end
end
View
@@ -10,4 +10,9 @@ def self.kipers_best_available
def self.undrafted
Player.find(:all, :conditions => {:drafted => false})
end
+
+ def self.filter_position(position)
+ players = Player.find(:all, :conditions => {:position => position, :drafted => false})
+ players.sort_by{|player| player['name']}
+ end
end
@@ -13,8 +13,7 @@
<%= @pick.team.name %>
</p>
-<%= render :partial => '/players/players'%>
-
+<%= render :partial => '/players/players', :locals => {:players => @players}%>
<p>
<%= link_to "Edit", edit_pick_path(@pick) %> |
<%= link_to "Destroy", @pick, :confirm => 'Are you sure?', :method => :delete %> |
@@ -1,6 +1,25 @@
-<% Player.undrafted.each do |player| %>
- <li><%= player.name %>
- <%= player.position %>
- <%= link_to 'Draft Player', draft_player_path(player) %></li>
+<h1>Players still undrafted</h1>
+<%= link_to "QB", undrafted_path(:position => "QB")%> |
+<%= link_to "WR", undrafted_path(:position => "WR")%> |
+<%= link_to "C", undrafted_path(:position => "C")%> |
+<%= link_to "CB", undrafted_path(:position => "CB")%> |
+<%= link_to "DE", undrafted_path(:position => "DE")%> |
+<%= link_to "DT", undrafted_path(:position => "DT")%> |
+<%= link_to "FB", undrafted_path(:position => "FB")%> |
+<%= link_to "FS", undrafted_path(:position => "FS")%> |
+<%= link_to "ILB", undrafted_path(:position => "ILB")%> |
+<%= link_to "OLB", undrafted_path(:position => "OLB")%> |
+<%= link_to "LS", undrafted_path(:position => "LS")%> |
+<%= link_to "OG", undrafted_path(:position => "OG")%> |
+<%= link_to "OT", undrafted_path(:position => "OT")%> |
+<%= link_to "RB", undrafted_path(:position => "RB")%> |
+<%= link_to "TE", undrafted_path(:position => "TE")%> |
+<%= link_to "SS", undrafted_path(:position => "SS")%> |
+<%= link_to "P", undrafted_path(:position => "P")%> |
+<%= link_to "K", undrafted_path(:position => "K")%>
+<br>
+<% players.each do |player| %>
+ <li><%= player.name %>
+ <%= player.position %></li>
<% end %>
@@ -1,5 +1 @@
-Players still undrafted
-<% @players.each do |player| %>
- <li><%= player.name %>
- <%= player.position %></li>
-<% end %>
+<%= render :partial => 'players', :locals => {:players => @players}%>
Oops, something went wrong.

0 comments on commit 05bc01f

Please sign in to comment.