Files
turbovault-app/app/controllers/items_controller.rb
2026-03-28 19:24:29 -04:00

60 lines
1.3 KiB
Ruby

class ItemsController < ApplicationController
before_action :require_authentication
before_action :set_item, only: [ :show, :edit, :update, :destroy ]
def index
@items = current_user.items.includes(:platform).order(date_added: :desc).page(params[:page]).per(25)
@platforms = Platform.order(:name)
end
def show
end
def new
@item = current_user.items.build
@platforms = Platform.order(:name)
end
def create
@item = current_user.items.build(item_params)
if @item.save
redirect_to @item, notice: "Item was successfully created."
else
@platforms = Platform.order(:name)
render :new, status: :unprocessable_entity
end
end
def edit
@platforms = Platform.order(:name)
end
def update
if @item.update(item_params)
redirect_to @item, notice: "Item was successfully updated."
else
@platforms = Platform.order(:name)
render :edit, status: :unprocessable_entity
end
end
def destroy
@item.destroy
redirect_to items_path, notice: "Item was successfully deleted."
end
private
def set_item
@item = current_user.items.find(params[:id])
end
def item_params
params.require(:item).permit(
:name, :item_type, :platform_id, :condition, :price_paid,
:location, :date_added, :notes, :igdb_id
)
end
end