Sha256: 99d9175d418880bf6020979a12fa0f314d65953269f5f33b8c294e1a51197a0d

Contents?: true

Size: 1.34 KB

Versions: 8

Compression:

Stored size: 1.34 KB

Contents

require_dependency "notee/application_controller"

module Notee
  class CategoriesController < ApplicationController
    before_action :set_category, only: [:update, :destroy]

    def index
      @categories = Category.all
      render json: { status: 'success', categories: @categories}
    end

    def create
      @category = Category.new(category_params)
      respond_to do |format|
        if @category.save
          format.json { render json: @category, status: 200 }
        else
          format.json { render json: @category.errors, status: :unprocessable_entity }
        end
      end
    end

    def update
      respond_to do |format|
        if @category.update(category_params)
          format.json { render json: @category, status: 200 }
        else
          format.json { render json: @category.errors, status: :unprocessable_entity }
        end
      end
    end

    def destroy
      respond_to do |format|
        if @category.destroy
          format.json { render json: @category, status: 200 }
        else
          format.json { render json: @category.errors, status: :internal_server_error }
        end
      end
    end

    private

    def category_params
      params.require(:category).permit(:name, :slug, :parent_id, :status)
    end

    def set_category
      @category = Category.find_by(id: params[:id])
    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
notee-0.3.3 app/controllers/notee/categories_controller.rb
notee-0.3.2 app/controllers/notee/categories_controller.rb
notee-0.3.1 app/controllers/notee/categories_controller.rb
notee-0.3.0 app/controllers/notee/categories_controller.rb
notee-0.2.9 app/controllers/notee/categories_controller.rb
notee-0.2.8 app/controllers/notee/categories_controller.rb
notee-0.2.7 app/controllers/notee/categories_controller.rb
notee-0.2.6 app/controllers/notee/categories_controller.rb