Stashing played hand
This commit is contained in:
parent
b6a570edf8
commit
fc5ef4ce32
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user