mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 04:02:53 +00:00
Moving to github
This commit is contained in:
59
app/controllers/items_controller.rb
Normal file
59
app/controllers/items_controller.rb
Normal file
@@ -0,0 +1,59 @@
|
||||
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
|
||||
Reference in New Issue
Block a user