48 lines
816 B
Ruby
48 lines
816 B
Ruby
class ClipsController < ApplicationController
|
|
allow_unauthenticated_access only: %i[ index show ]
|
|
before_action :set_clip, only: %i[ show edit update destroy ]
|
|
def index
|
|
@clips = Clip.all
|
|
end
|
|
|
|
def show
|
|
end
|
|
|
|
def new
|
|
@clip = Clip.new
|
|
end
|
|
|
|
def create
|
|
@clip = Clip.new(clip_params)
|
|
if @clip.save
|
|
redirect_to @clip
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @clip.update(clip_params)
|
|
redirect_to @clip
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@clip.destroy
|
|
redirect_to clips_path
|
|
end
|
|
|
|
private
|
|
def set_clip
|
|
@clip = Clip.find(params[:id])
|
|
end
|
|
|
|
def clip_params
|
|
params.expect(clip: [ :title, :video, :category_id ])
|
|
end
|
|
end
|