diff options
author | Ben Harris <ben@tilde.team> | 2022-01-15 12:10:26 -0500 |
---|---|---|
committer | Ben Harris <ben@tilde.team> | 2022-01-15 12:10:26 -0500 |
commit | 2c8c227493509175fcdbcba3e6a85f8b954a169e (patch) | |
tree | 56c95cb471004fef1bfa4c99e93fdec1716e3840 /app/controllers/machines_controller.rb |
init
Diffstat (limited to 'app/controllers/machines_controller.rb')
-rw-r--r-- | app/controllers/machines_controller.rb | 71 |
1 files changed, 71 insertions, 0 deletions
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 |