Skip to content

Commit

Permalink
Removed duplication in views
Browse files Browse the repository at this point in the history
  • Loading branch information
lisahamm committed Feb 25, 2015
1 parent c13e298 commit e9bd162
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
15 changes: 10 additions & 5 deletions tic_tac_toe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ class TicTacToeController < Sinatra::Base
end

post '/setup' do
redirect to('/invalid_setup') if params[:player_mark] == nil || params[:opponent] == nil
session[:mark] = params[:player_mark]
session[:opponent] = params[:opponent]
redirect to('/game')
if params[:player_mark] || params[:opponent] == nil
session[:invalid_input_message] = "Please select an option to continue"
redirect to('/invalid_setup')
else
session[:mark] = params[:player_mark]
session[:opponent] = params[:opponent]
redirect to('/game')
end
end

get '/invalid_setup' do
erb :index_with_validation_messages
@invalid_input_message = session[:invalid_input_message]
erb :index
end

get '/game' do
Expand Down
10 changes: 9 additions & 1 deletion views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
<input type="radio" name="player_mark" value="O" />O
</div>

<% if params[:player_mark] == nil %>
<p><%= @invalid_input_message %></p>
<% end %>

<div class="form-section">
Would you like to play against the computer?:
<input type="radio" name="opponent" value="yes" />Yes
<input type="radio" name="opponent" value="no" />No
</div>

<% if params[:opponent] == nil %>
<p><%= @invalid_input_message %></p>
<% end %>

<div class="form-section">
<input id="setup-submit" type ="submit" value="Submit" />
</div>
</form>
</div>
</div>
29 changes: 0 additions & 29 deletions views/index_with_validation_messages.erb

This file was deleted.

0 comments on commit e9bd162

Please sign in to comment.