diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/concerns/.keep | 0 | ||||
-rw-r--r-- | app/controllers/machines_controller.rb | 49 | ||||
-rw-r--r-- | app/controllers/players_controller.rb | 50 |
4 files changed, 101 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..09705d1 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,2 @@ +class ApplicationController < ActionController::Base +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/controllers/concerns/.keep diff --git a/app/controllers/machines_controller.rb b/app/controllers/machines_controller.rb new file mode 100644 index 0000000..24c90e7 --- /dev/null +++ b/app/controllers/machines_controller.rb @@ -0,0 +1,49 @@ +class MachinesController < ApplicationController + def index + @machines = Machine.order("name") + end + + def show + @machine = Machine.find(params[:id]) + end + + def new + @machine = Machine.new + end + + def create + @machine = Machine.new(machine_params) + + if @machine.save + redirect_to @machine + else + render :new + end + end + + def edit + @machine = Machine.find(params[:id]) + end + + def update + @machine = Machine.find(params[:id]) + + if @machine.update(machine_params) + redirect_to @machine + else + render :edit + end + end + + def destroy + @machine = Machine.find(params[:id]) + @machine.destroy + + redirect_to root_path + end + + private + 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..e129114 --- /dev/null +++ b/app/controllers/players_controller.rb @@ -0,0 +1,50 @@ +class PlayersController < ApplicationController + def index + @players = Player.order("name") + end + + def show + @player = Player.find(params[:id]) + end + + def new + @player = Player.new + end + + def create + @player = Player.new(player_params) + + if @player.save + redirect_to @player + else + render :new + end + end + + def edit + @player = Player.find(params[:id]) + end + + def update + @player = Player.find(params[:id]) + + if @player.update(player_params) + redirect_to @player + else + render :edit + end + end + + def destroy + @player = Player.find(params[:id]) + @player.destroy + + redirect_to player_path + end + + private + def player_params + params.require(:player).permit(:name, :paid, :strikes) + end + +end |