Skip to content

Instantly share code, notes, and snippets.

@leemcalilly
Created July 2, 2013 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemcalilly/a47466504b7783b31773 to your computer and use it in GitHub Desktop.
Save leemcalilly/a47466504b7783b31773 to your computer and use it in GitHub Desktop.
class CheckoutsController < ApplicationController
before_filter :require_login
before_action :set_checkout, only: [:show, :edit, :update, :destroy]
before_action :correct_user, only: [:show, :edit, :update, :destroy]
# GET /checkouts
def index
@user = current_user
@checkouts = @user.checkouts.to_a
end
# GET /checkouts/1
def show
@user = current_user
@checkouts = @user.checkouts.to_a
end
# GET /checkouts/new
def new
@user = current_user
@checkout = @user.checkouts.new
end
# GET /checkouts/1/edit
def edit
@user = current_user
@checkout = Checkout.find(params[:id])
end
# POST /checkouts
def create
@user = current_user
@checkout = @user.checkouts.build(checkout_params)
respond_to do |format|
if @checkout.save
format.html { redirect_to @checkout, notice: 'Checkout was successfully created.' }
else
format.html { render action: 'new' }
end
end
end
# PATCH/PUT /checkouts/1
def update
respond_to do |format|
if @checkout.update(checkout_params)
format.html { redirect_to @checkout, notice: 'Checkout was successfully updated.' }
else
format.html { render action: 'edit' }
end
end
end
# DELETE /checkouts/1
def destroy
@checkout.destroy
respond_to do |format|
format.html { redirect_to checkouts_url }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_checkout
@checkout = Checkout.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def checkout_params
params.require(:checkout).permit(:job, :employee_ids, :shift, :date, :hours, :sales, :tips, :owed, :collected, :notes)
end
def correct_user
@checkout = current_user.checkouts.find_by(id: params[:id])
redirect_to checkouts_path if @checkout.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment