From 2c8c227493509175fcdbcba3e6a85f8b954a169e Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 15 Jan 2022 12:10:26 -0500 Subject: init --- app/controllers/application_controller.rb | 4 ++ app/controllers/concerns/.keep | 0 app/controllers/machines_controller.rb | 71 +++++++++++++++++++++++++++++++ app/controllers/players_controller.rb | 71 +++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/machines_controller.rb create mode 100644 app/controllers/players_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..7944f9f --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/machines_controller.rb b/app/controllers/machines_controller.rb new file mode 100644 index 0000000..d83a52f --- /dev/null +++ b/app/controllers/machines_controller.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +class MachinesController < ApplicationController + before_action :set_machine, only: %i[show edit update destroy] + + # GET /machines or /machines.json + def index + @machines = Machine.all + end + + # GET /machines/1 or /machines/1.json + def show; end + + # GET /machines/new + def new + @machine = Machine.new + end + + # GET /machines/1/edit + def edit; end + + # POST /machines or /machines.json + def create + @machine = Machine.new(machine_params) + + respond_to do |format| + if @machine.save + format.html { redirect_to machine_url(@machine), notice: 'Machine was successfully created.' } + format.json { render :show, status: :created, location: @machine } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @machine.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /machines/1 or /machines/1.json + def update + respond_to do |format| + if @machine.update(machine_params) + format.html { redirect_to machine_url(@machine), notice: 'Machine was successfully updated.' } + format.json { render :show, status: :ok, location: @machine } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @machine.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /machines/1 or /machines/1.json + def destroy + @machine.destroy + + respond_to do |format| + format.html { redirect_to machines_url, notice: 'Machine was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + + # Use callbacks to share common setup or constraints between actions. + def set_machine + @machine = Machine.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def machine_params + params.require(:machine).permit(:name, :edition) + end +end 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 -- cgit 1.4.1