playground/app/controllers/scraps_controller.rb

54 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

2026-05-17 03:44:36 +00:00
class ScrapsController < ApplicationController
allow_unauthenticated_access(only: %i[index show])
def index
@scraps = Scrap.order(created_at: :desc)
2026-05-17 03:44:36 +00:00
end
def edit
@scrap = Scrap.find(params[:id])
end
def update
@scrap = Scrap.find(params[:id])
if @scrap.update(scrap_params)
redirect_to posts_path, notice: "scrap edited."
else
render :edit, status: :unprocessable_entity, notice: "U fucked up somewhere."
end
end
def new
@scrap = Scrap.new
end
def create
@scrap = Scrap.new(scrap_params)
if @scrap.save
redirect_to scraps_path, notice: "scrap created."
else
render :new, status: :unprocessable_entity, notice: "U fucked up somewhere."
end
end
def destroy
@scrap = Scrap.find(params[:id])
@scrap.destroy
redirect_to scrap_path(@scrap), notice: "Member deleted."
end
def show
@scrap = Scrap.find_by(id: params[:id])
if @scrap.nil?
flash[:alert] = "Scrapbook entry not found"
redirect_to scraps_path
return
end
end
private
def scrap_params
params.require(:scrap).permit(:text, :image, :music, :mood, :notes)
end
end