Skip to content

Instantly share code, notes, and snippets.

@rosiehoyem
Last active August 29, 2015 14:17
Show Gist options
  • Save rosiehoyem/8791c52b63b1af19688d to your computer and use it in GitHub Desktop.
Save rosiehoyem/8791c52b63b1af19688d to your computer and use it in GitHub Desktop.
Tracking Checkouts
class CheckoutsController < ApplicationController
...
def create
@checkout = @item.checkouts.build(checkout_params)
respond_to do |format|
if @checkout.save
if @checkout.reservation == true
@checkout.create_activity :reservation, options = { owner: Person.find(@checkout.checked_out_by), recipient: @item, approved_by_id: @user.id }
else
@checkout.create_activity :create, options = { owner: Person.find(@checkout.checked_out_by), recipient: @item, approved_by_id: @user.id }
end
format.html { redirect_to checkouts_path, notice: 'Checkout was successfully created.' }
format.json { render json: @checkout, status: :created, location: @checkout }
else
format.html { render :new }
format.json { render json: @checkout.errors, status: :unprocessable_entity }
end
end
...
end
class Checkout < ActiveRecord::Base
include PublicActivity::Common
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment