1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-05 16:24:21 +01:00
fab-manager/app/controllers/api/credits_controller.rb
2016-03-23 18:39:41 +01:00

48 lines
1.0 KiB
Ruby

class API::CreditsController < API::ApiController
before_action :authenticate_user!
before_action :set_credit, only: [:show, :update, :destroy]
def index
authorize Credit
if params
@credits = Credit.includes(:creditable).where(params.permit(:creditable_type))
else
@credits = Credit.includes(:creditable).all
end
end
def create
authorize Credit
@credit = Credit.new(credit_params)
if @credit.save
render :show, status: :created, location: @credit
else
render json: @credit.errors, status: :unprocessable_entity
end
end
def update
authorize Credit
if @credit.update(credit_params)
render :show, status: :ok, location: @credit
else
render json: @credit.errors, status: :unprocessable_entity
end
end
def destroy
authorize Credit
@credit.destroy
head :no_content
end
private
def set_credit
@credit = Credit.find(params[:id])
end
def credit_params
params.require(:credit).permit!
end
end