misadventure/app/controllers/tapes_controller.rb

48 lines
802 B
Ruby

class TapesController < ApplicationController
allow_unauthenticated_access only: %i[ index show ]
before_action :set_tape, only: %i[ show edit update destroy ]
def index
@tapes = Tape.all
end
def show
end
def new
@tape = Tape.new
end
def create
@tape = Tape.new(tape_params)
if @tape.save
redirect_to @tape
else
render :new, status: :unprocessable_entity
end
end
def edit
end
def update
if @tape.update(tape_params)
redirect_to @tape
else
render :edit, status: :unprocessable_entity
end
end
def destroy
@tape.destroy
redirect_to tapes_path
end
private
def set_tape
@tape = Tape.find(params[:id])
end
def tape_params
params.expect(tape: [ :title, :video ])
end
end