1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/controllers/api/custom_assets_controller.rb
Sylvain 0cd841da33 rubocop api controllers
TODO:
 - events controller
 - availabilies controller
 - members controller
 - plans controller
2019-01-16 16:28:25 +01:00

45 lines
1.2 KiB
Ruby

# frozen_string_literal: true
# API Controller for resources of type CustomAsset
# CustomAssets are used in settings
class API::CustomAssetsController < API::ApiController
before_action :authenticate_user!, only: %i[index update create destroy]
before_action :set_custom_asset, only: %i[show update destroy]
# PUT /api/custom_assets/1/
def update
authorize CustomAsset
if @custom_asset.update(custom_asset_params.permit!)
render :show, status: :ok, location: @custom_asset
else
render json: @custom_asset.errors, status: :unprocessable_entity
end
end
# POST /api/custom_assets/
def create
authorize CustomAsset
@custom_asset = CustomAsset.new(custom_asset_params.permit!)
if @custom_asset.save
render :show, status: :created, location: @custom_asset
else
render json: @custom_asset.errors, status: :unprocessable_entity
end
end
# GET /api/custom_assets/1/
def show; end
private
def set_custom_asset
@custom_asset = CustomAsset.find_by(name: params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def custom_asset_params
params.required(:custom_asset).permit(:name, custom_asset_file_attributes: [:attachment])
end
end