2021-08-21 23:30:19 +00:00
|
|
|
class MachinesController < ApplicationController
|
2021-08-22 03:43:16 +00:00
|
|
|
def random
|
|
|
|
@machine = Machine.order(Arel.sql("RANDOM()")).first
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
|
2021-08-21 23:30:19 +00:00
|
|
|
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
|
|
|
|
|
2021-08-22 03:43:16 +00:00
|
|
|
redirect_to machines_path
|
2021-08-21 23:30:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def machine_params
|
|
|
|
params.require(:machine).permit(:name, :edition)
|
|
|
|
end
|
|
|
|
end
|