Sha256: ffa67dce7d204718ed0189cc2c43043bba5ad8f83a8c4522fb30f59e45bdfb52

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

module Kms
  class SnippetsController < ApplicationController
    load_and_authorize_resource
    respond_to :json

    def index
      render json: Snippet.all, root: false
    end

    def create
      @snippet = Snippet.new(snippet_params)
      if @snippet.save
        head :no_content
      else
        render json: {errors: @snippet.errors}.to_json, status: :unprocessable_entity
      end
    end

    def update
      @snippet = Snippet.find(params[:id])
      if @snippet.update(snippet_params)
        head :no_content
      else
        render json: {errors: @snippet.errors}.to_json, status: :unprocessable_entity
      end
    end

    def show
      @snippet = Snippet.find(params[:id])
      render json: @snippet, root: false
    end

    def destroy
      @snippet = Snippet.find(params[:id])
      @snippet.destroy
      head :no_content
    end

    protected

    def snippet_params
      params.require(:snippet).permit(:name, :slug, :content)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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