69 lines
1.8 KiB
Ruby
69 lines
1.8 KiB
Ruby
# 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.order(:name)
|
|
end
|
|
|
|
# GET /players/1 or /players/1.json
|
|
def show; end
|
|
|
|
# GET /players/new
|
|
def new
|
|
@player = Player.new
|
|
end
|
|
|
|
# POST /players or /players.json
|
|
def create
|
|
@player = Player.new(player_params)
|
|
|
|
respond_to do |format|
|
|
if @player.save
|
|
format.html { redirect_to players_url, notice: "Added #{@player.name}." }
|
|
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 players_url, notice: "Updated #{@player.name}." }
|
|
format.json { render :show, status: :ok, location: @player }
|
|
else
|
|
format.html { render :show, 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, status: :see_other, notice: 'Player was successfully removed.' }
|
|
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
|