Skip to content

Instantly share code, notes, and snippets.

@pschyska
Created October 10, 2012 14:51
Show Gist options
  • Save pschyska/3866111 to your computer and use it in GitHub Desktop.
Save pschyska/3866111 to your computer and use it in GitHub Desktop.
class EasypepApi::V1::ShiftsController < EasypepApi::ApplicationController
load_and_authorize_resource
before_filter :find_shift, :except => [:index, :create]
respond_to :json
def index
@shifts = parent_ressource.shifts.accessible_by(current_ability)
respond_with(@shifts)
end
def show
respond_with(@shift)
end
def new
@shift = parent_ressource.shifts.new
respond_with(@shift)
end
def create
@shift = parent_ressource.shifts.new(params[:shift])
@shift.save
respond_with(@shift) # should put Location: to show or render show directly
end
def update
@shift.update_attributes(params[:shift])
respond_with(@shift) # should render show
end
def destroy
@shift.destroy
respond_with(:status => :ok)
end
private
def parent_ressource
if current_schedule.present?
return current_schedule
else
return current_account
end
end
def find_shift
@shift = current_account.shifts.find(params[:id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment