Start adding New Game button to table

This commit is contained in:
Jesse C. Fisher 2019-10-28 07:08:38 -07:00
parent 6298225be5
commit 8b3a3e0dde
7 changed files with 28 additions and 8 deletions

View File

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

View File

@ -1,5 +1,5 @@
class TablesController < ApplicationController 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 respond_to :html, :json
@ -39,6 +39,11 @@ class TablesController < ApplicationController
end end
end end
def new_game
@table.add_game
redirect_to @table
end
# GET /tables/new # GET /tables/new
def new def new
@table = Table.new @table = Table.new

View File

@ -181,6 +181,11 @@ private
def add_table def add_table
self.table ||= Table.create current_game_id: self.id self.table ||= Table.create current_game_id: self.id
self.seats = self.table.seats 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 self.save
end end

View File

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

View File

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

View File

@ -10,8 +10,12 @@
%p= @table.title %p= @table.title
- if @game.startable? && @game.already_has?(current_user) - if @game.already_has?(current_user)
= button_to 'Start', start_game_path(@game) - 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 -# .players
%b Players: %b Players:

View File

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