about summary refs log tree commit diff
path: root/app/controllers/players_controller.rb
diff options
context:
space:
mode:
authorBen Harris <ben@tilde.team>2022-01-15 12:10:26 -0500
committerBen Harris <ben@tilde.team>2022-01-15 12:10:26 -0500
commit2c8c227493509175fcdbcba3e6a85f8b954a169e (patch)
tree56c95cb471004fef1bfa4c99e93fdec1716e3840 /app/controllers/players_controller.rb
init
Diffstat (limited to 'app/controllers/players_controller.rb')
-rw-r--r--app/controllers/players_controller.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/app/controllers/players_controller.rb b/app/controllers/players_controller.rb
new file mode 100644
index 0000000..c1139e1
--- /dev/null
+++ b/app/controllers/players_controller.rb
@@ -0,0 +1,71 @@
+# frozen_string_literal: true
+
+class PlayersController < ApplicationController
+  before_action :set_player, only: %i[show edit update destroy]
+
+  # GET /players or /players.json
+  def index
+    @players = Player.all
+  end
+
+  # GET /players/1 or /players/1.json
+  def show; end
+
+  # GET /players/new
+  def new
+    @player = Player.new
+  end
+
+  # GET /players/1/edit
+  def edit; end
+
+  # POST /players or /players.json
+  def create
+    @player = Player.new(player_params)
+
+    respond_to do |format|
+      if @player.save
+        format.html { redirect_to player_url(@player), notice: 'Player was successfully created.' }
+        format.json { render :show, status: :created, location: @player }
+      else
+        format.html { render :new, status: :unprocessable_entity }
+        format.json { render json: @player.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  # PATCH/PUT /players/1 or /players/1.json
+  def update
+    respond_to do |format|
+      if @player.update(player_params)
+        format.html { redirect_to player_url(@player), notice: 'Player was successfully updated.' }
+        format.json { render :show, status: :ok, location: @player }
+      else
+        format.html { render :edit, status: :unprocessable_entity }
+        format.json { render json: @player.errors, status: :unprocessable_entity }
+      end
+    end
+  end
+
+  # DELETE /players/1 or /players/1.json
+  def destroy
+    @player.destroy
+
+    respond_to do |format|
+      format.html { redirect_to players_url, notice: 'Player was successfully destroyed.' }
+      format.json { head :no_content }
+    end
+  end
+
+  private
+
+  # Use callbacks to share common setup or constraints between actions.
+  def set_player
+    @player = Player.find(params[:id])
+  end
+
+  # Only allow a list of trusted parameters through.
+  def player_params
+    params.require(:player).permit(:name, :paid, :strikes)
+  end
+end