mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 21:02:52 +00:00
60 lines
1.3 KiB
Ruby
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
|