Sha256: e4af92f388929a2568b7eba9dabe29ea6501b0f3449320bc34c9df3c59e9c016

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

module JeraPush
  class JeraPushController < ::ApplicationController
    protected

    def render_invalid_params
      render nothing: true, status: :unprocessable_entity
    end

    def render_not_found
      render nothing: true, status: :not_found
    end

    def render_object(object)
      if object.nil? || object.errors.any?
        render_unprocessable_entity(object)
      else
        render_object_success(object)
      end
    end

    private

    def render_object_success(object)
      render json: { data: object, status: :success }, status: :ok
    end

    def render_unprocessable_entity(object)
      render json: {
          data: object,
          errors: object.errors.full_messages,
          status: :unprocessable_entity
        }, status: :ok
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jera_push-2.1.4 app/controllers/jera_push/jera_push_controller.rb
jera_push-2.1.3 app/controllers/jera_push/jera_push_controller.rb
jera_push-2.1.2 app/controllers/jera_push/jera_push_controller.rb