-
-
Save leemcalilly/6e01ff8b86b1bdd078ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, :shift, :employee_ids, :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