Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically Removed Whitespace #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions README
@@ -1,7 +1,7 @@
== Welcome to Rails

Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.
Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.

This pattern splits the view (also called the presentation) into "dumb" templates
that are primarily responsible for inserting pre-built data in between HTML tags.
Expand Down Expand Up @@ -57,14 +57,14 @@ Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
#
# Example:
# RewriteCond %{REQUEST_URI} ^/notrails.*
# RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
Expand All @@ -85,7 +85,7 @@ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
#
# Example:
# ErrorDocument 500 /500.html

Expand Down Expand Up @@ -132,7 +132,7 @@ and also on programming in general.

Debugger support is available through the debugger command when you start your Mongrel or
Webrick server with --debugger. This means that you can break out of execution at any point
in the code, investigate and change the model, AND then resume execution!
in the code, investigate and change the model, AND then resume execution!
You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
Example:

Expand Down
22 changes: 11 additions & 11 deletions app/controllers/picks_controller.rb
@@ -1,46 +1,46 @@
class PicksController < ApplicationController

def home
@pick = Pick.current
@end_of_draft = @pick.nil?
@previous_picks = Pick.previous_picks
end

def index
@picks = Pick.all
end

def show
@pick = Pick.find(params[:id])
@players = Player.undrafted
end

def draft_player

player = Player.find(params[:id])

unless player.drafted
draft_over = Pick.current.team.draft(player)

respond_to do |format|
if (!draft_over && player.save)
flash[:notice] = 'Player was successfully drafted.'
format.html { redirect_to(pick_path(Pick.current)) }
else
flash[:notice] = 'The Draft is over, cannot pick more players,
flash[:notice] = 'The Draft is over, cannot pick more players,
or there was an error drafting the player you selected'
format.html { redirect_to(root_path) }
end
end

else
flash[:notice] = 'That player has already been drafted'
redirect_to(pick_path(Pick.current))
end
end

def results
@draft_results = Pick.results
end

end
4 changes: 2 additions & 2 deletions app/controllers/players_controller.rb
Expand Up @@ -2,11 +2,11 @@ class PlayersController < ApplicationController
def index
@players = Player.all
end

def show
@player = Player.find(params[:id])
end

def undrafted
unless params[:position.nil?]
@players = Player.filter_position(params[:position])
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/sessions_controller.rb
@@ -1,7 +1,7 @@
class SessionsController < ApplicationController
def new
end

def create
user = User.authenticate(params[:login], params[:password])
if user
Expand All @@ -13,7 +13,7 @@ def create
redirect_to_target_or_default(root_url)
end
end

def destroy
session[:user_id] = nil
flash[:notice] = "You have been logged out."
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/teams_controller.rb
Expand Up @@ -2,9 +2,9 @@ class TeamsController < ApplicationController
def index
@teams = Team.all
end

def show
@team = Team.find(params[:id])
end

end
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -2,7 +2,7 @@ class UsersController < ApplicationController
def new
@user = User.new
end

def create
@user = User.new(params[:user])
if @user.save
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/layout_helper.rb
Expand Up @@ -7,15 +7,15 @@ def title(page_title, show_title = true)
@content_for_title = page_title.to_s
@show_title = show_title
end

def show_title?
@show_title
end

def stylesheet(*args)
content_for(:head) { stylesheet_link_tag(*args) }
end

def javascript(*args)
content_for(:head) { javascript_include_tag(*args) }
end
Expand Down
22 changes: 11 additions & 11 deletions app/models/pick.rb
@@ -1,42 +1,42 @@
class Pick < ActiveRecord::Base
has_one :player
has_one :team

validates_presence_of :team_id

def team
Team.find(self.team_id)
end

def self.results
Pick.find(:all, :conditions => {:used => true})
end

def self.current
Pick.first(:conditions => {:used => false})
end

def self.previous
pick = Pick.current
unless(pick.pick_number == 1)
Pick.find_by_pick_number(pick.pick_number-1)
else
pick
end

end

def self.next
Pick.find_by_pick_number(Pick.current.pick_number+1)
end
def self.previous_picks

def self.previous_picks
picks = Pick.find(:all, :conditions => {:used => true})
#technically they should already be sorted, but to be robust
picks.sort_by {|pick| pick['pick_number']}
picks.reverse!
picks = picks[0...3]
end


end
8 changes: 4 additions & 4 deletions app/models/player.rb
@@ -1,16 +1,16 @@
class Player < ActiveRecord::Base
belongs_to :team
belongs_to :pick


def self.kipers_best_available
Player.first(:conditions => {:drafted => false})
end

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']}
Expand Down
22 changes: 11 additions & 11 deletions app/models/team.rb
@@ -1,12 +1,12 @@
class Team < ActiveRecord::Base
belongs_to :pick
has_many :players

def kiper_draft
player = Player.kipers_best_available
do_drafting(player,self)
player = Player.kipers_best_available
do_drafting(player,self)
end

def draft(player)
unless Pick.current.pick_number == 255
do_drafting(player,self)
Expand All @@ -15,16 +15,16 @@ def draft(player)
draft_over = true
end
end




protected

def do_drafting(player, team)
player.drafted = true
player.save

current_pick = Pick.current
current_pick.player = player
current_pick.player_id = player.id
Expand All @@ -33,5 +33,5 @@ def do_drafting(player, team)
team.players.push(player)

end

end
14 changes: 7 additions & 7 deletions app/models/user.rb
@@ -1,37 +1,37 @@
class User < ActiveRecord::Base
# new columns need to be added here to be writable through mass assignment
attr_accessible :username, :email, :password, :password_confirmation

attr_accessor :password
before_save :prepare_password

validates_presence_of :username
validates_uniqueness_of :username, :email, :allow_blank => true
validates_format_of :username, :with => /^[-\w\._@]+$/i, :allow_blank => true, :message => "should only contain letters, numbers, or .-_@"
validates_format_of :email, :with => /^[-a-z0-9_+\.]+\@([-a-z0-9]+\.)+[a-z0-9]{2,4}$/i
validates_presence_of :password, :on => :create
validates_confirmation_of :password
validates_length_of :password, :minimum => 4, :allow_blank => true

# login can be either username or email address
def self.authenticate(login, pass)
user = find_by_username(login) || find_by_email(login)
return user if user && user.matching_password?(pass)
end

def matching_password?(pass)
self.password_hash == encrypt_password(pass)
end

private

def prepare_password
unless password.blank?
self.password_salt = Digest::SHA1.hexdigest([Time.now, rand].join)
self.password_hash = encrypt_password(password)
end
end

def encrypt_password(pass)
Digest::SHA1.hexdigest([pass, password_salt].join)
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Expand Up @@ -19,11 +19,11 @@
<%- flash.each do |name, msg| -%>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
<%- end -%>

<%- if show_title? -%>
<h1><%=h yield(:title) %></h1>
<%- end -%>

<%= yield %>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion app/views/picks/home.html.erb
Expand Up @@ -14,7 +14,7 @@
<h2><%= pick.team.name %></h2>
Who drafted <li><%= pick.player.name%>, <%=pick.player.position%></li>
<% end %>

<h2>The next pick will be</h2>
<li><%= Pick.next.team.name %></li>

Expand Down
2 changes: 1 addition & 1 deletion app/views/picks/results.html.erb
Expand Up @@ -3,5 +3,5 @@
<% @draft_results.each do |result| %>
Round <%= result.round %>
Pick <%= result.pick_number %>
<li><%= result.player.name %> , <%= result.player.position %></li><br>
<li><%= result.player.name %> , <%= result.player.position %></li><br>
<% end %>
2 changes: 1 addition & 1 deletion app/views/players/_players.html.erb
Expand Up @@ -26,5 +26,5 @@
<% unless pick.nil? %>
<%= link_to 'Draft Player', draft_player_path(pick) %></li>
<% end %>

<% end %>
2 changes: 1 addition & 1 deletion app/views/teams/index.html.erb
Expand Up @@ -4,7 +4,7 @@ Teams
<% @teams.each do |team|%>
<h2><%= team.name %>
<%= team.division %></h2>

<% team.players.each do |player|%>
<li>
Pick Number <%= player.pick.pick_number %>
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/inflections.rb
@@ -1,6 +1,6 @@
# Be sure to restart your server when you modify this file.

# Add new inflection rules using the following format
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
Expand Down