Sha256: a1515a47005faa5f7adda2e493ea868c86233d0207cd121ba545d6df7942f86a

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module Kms
  class TemplatesController < ApplicationController
    load_and_authorize_resource
    def index
      render json: Template.all
    end

    def create
      @template = Template.new(template_params)
      @template.content = TemplateProcessor.new(@template).process
      if @template.save
        head :no_content
      else
        render json: {errors: @template.errors}.to_json, status: :unprocessable_entity
      end
    end

    def update
      @template = Template.find(params[:id])
      if @template.update(template_params)
        render json: @template.to_json
      else
        render json: @template.to_json(methods: :errors), status: :unprocessable_entity
      end
    end

    def show
      @template = Template.find(params[:id])
      render json: @template.to_json
    end

    def destroy
      @template = Template.find(params[:id])
      @template.destroy
      render json: @template.to_json
    end

    protected

    def template_params
      params.require(:template).permit(:name, :content)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kms-1.1.0 app/controllers/kms/templates_controller.rb
kms-1.0.1 app/controllers/kms/templates_controller.rb
kms-1.0.0 app/controllers/kms/templates_controller.rb