From fc5ef4ce3202578b455b9b0756394bf5e86cc776 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Sun, 3 May 2015 06:05:31 -0700 Subject: [PATCH] Stashing played hand --- app/controllers/games_controller.rb | 10 +++++++++- app/models/game.rb | 4 ++++ app/views/games/show.html.haml | 8 ++++---- config/routes.rb | 3 +++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index cbc00c77..312a53c1 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,5 +1,5 @@ class GamesController < ApplicationController - before_action :set_game, only: [:show, :edit, :update, :destroy] + before_action :set_game, only: [:show, :edit, :update, :destroy, :play_hand] respond_to :html @@ -20,6 +20,14 @@ class GamesController < ApplicationController def edit end + def play_hand + # TODO validate player's turn, current_user == @game.current_player.user + @hand = params[:player_card_ids] + # TODO add current_hand logic + # @hand > @game.hand_to_beat + redirect_to @game + end + def create @game = Game.new(title: game_params[:title]) if game_params[:player_ids] diff --git a/app/models/game.rb b/app/models/game.rb index 3ae125e8..778f6173 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -33,6 +33,10 @@ class Game < ActiveRecord::Base save end + def current_player + self.players.find_by(id: control_player_id) + end + def validate_startable @player_count = players.count errors[:players] = 'Must be at least 2 players.' if @player_count < 2 diff --git a/app/views/games/show.html.haml b/app/views/games/show.html.haml index 7a47c80d..0501e8f9 100644 --- a/app/views/games/show.html.haml +++ b/app/views/games/show.html.haml @@ -47,13 +47,13 @@ %h1 Hand to beat - else %h1 Open table + %h2= "Played #{@hand}" .controls - if @game.control_user == current_user - // Show the Play Hand form - -#= form_for @game, :url => {:action => "Bro"} do |f| - = form_for @game do |f| + // Play hand form + = form_for @game, :url => play_hand_game_path(@game) do |f| // Provide id of current game - = f.hidden_field :id + -#= f.hidden_field :id = f.submit "Play Hand" diff --git a/config/routes.rb b/config/routes.rb index c7f6d6a9..aa7d0de8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,9 @@ Rails.application.routes.draw do resources :games do get 'start' get 'join' + member do + patch 'play_hand' + end end mount Upmin::Engine => '/admin'