Start adding New Game button to table

This commit is contained in:
Jesse C. Fisher 2019-10-28 07:08:38 -07:00 committed by Jesse C. Fisher
parent 12ae163ecd
commit 5453be7d2d
7 changed files with 28 additions and 8 deletions

View File

@ -27,7 +27,8 @@
//// Show Game#show
button
button,
input[type=submit]
font-size: 4vmin
#table-component,

View File

@ -1,5 +1,5 @@
class TablesController < ApplicationController
before_action :set_table, only: [:show, :edit, :update, :destroy]
before_action :set_table, only: [:show, :edit, :update, :destroy, :new_game]
respond_to :html, :json
@ -39,6 +39,11 @@ class TablesController < ApplicationController
end
end
def new_game
@table.add_game
redirect_to @table
end
# GET /tables/new
def new
@table = Table.new

View File

@ -181,6 +181,11 @@ private
def add_table
self.table ||= Table.create current_game_id: self.id
self.seats = self.table.seats
self.seats.each do |seat|
if seat.user_id || seat.user_soft_token
new_player = self.players.create(user_id: seat.user_id, soft_token: seat.user_soft_token)
end
end
self.save
end

View File

@ -27,6 +27,11 @@ class Table < ActiveRecord::Base
self.games.last
end
def add_game
self.games.create
end
private
def add_seats
@ -35,7 +40,4 @@ class Table < ActiveRecord::Base
end
end
def add_game
self.games.create if self.current_game_id.blank?
end
end

View File

@ -19,7 +19,7 @@
-# Show player controls if player is owned by current_user
- if seat.player.soft_token == current_user.soft_token
= form_for(@game,
url: play_hand_game_path,
url: play_hand_game_path(@game),
method: "post",
name: "player_controls_" + seat.player_id.to_s,
id: "player_controls_" + seat.player_id.to_s) do |f|

View File

@ -10,8 +10,12 @@
%p= @table.title
- if @game.startable? && @game.already_has?(current_user)
= button_to 'Start', start_game_path(@game)
- if @game.already_has?(current_user)
- if @game.startable?
= button_to 'Start', start_game_path(@game)
- if @game.winner_player_id || @game.nil?
= button_to 'New Game', new_game_table_path(@table)
-# .players
%b Players:

View File

@ -1,6 +1,9 @@
Rails.application.routes.draw do
resources :players
resources :tables do
member do
post 'new_game'
end
resources :seats do
member do
patch 'sit'