Files
fizzy/app/controllers/splats_controller.rb
T
2024-07-24 14:35:24 -05:00

44 lines
715 B
Ruby

class SplatsController < ApplicationController
before_action :set_splat, only: [ :show, :edit, :update ]
def index
if params[:category_id]
@category = Category.find(params[:category_id])
@splats = @category.splats
else
@splats = Splat.all
end
end
def new
@splat = Splat.new
end
def edit
end
def update
@splat.update(splat_params)
redirect_to splat_path(@splat)
end
def create
Splat.create! splat_params
redirect_to splats_path
end
def show
end
private
def set_splat
@splat = Splat.find(params[:id])
end
def splat_params
params.require(:splat).permit(:title, :body, :color, category_ids: [])
end
end