Sha256: 7cff9235dbe212d11117c91a01b455cbada454b911477e1c9213d514aabddb5a

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RespondForHelper
  module Formats
    class Json < Base
      def respond
        respond_to do |format|
          format.json { yield }
        end
      end

      def _index
        render json: @item
      end

      def _show
        render json: @item
      end

      def _create
        if succeeded?
          render json: @item, status: :created
        else
          render json: @item.errors, status: :unprocessable_entity
        end
      end

      def _update
        if succeeded?
          render json: @item, status: :ok
        else
          render json: @item.errors, status: :unprocessable_entity
        end
      end

      def _destroy
        if succeeded?
          head :no_content
        else
          head :unprocessable_entity
        end
      end

      def default_action
        if succeeded?
          render json: @item, status: :ok
        else
          render json: @item.errors, status: :unprocessable_entity
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
respond_for_helper-1.0.2 lib/respond_for_helper/formats/json.rb
respond_for_helper-1.0.1 lib/respond_for_helper/formats/json.rb
respond_for_helper-1.0.0 lib/respond_for_helper/formats/json.rb