Sha256: c47975bf70518a36d714dc1732cf98acff011586d12e6d9e413db14436d9226f

Contents?: true

Size: 963 Bytes

Versions: 5

Compression:

Stored size: 963 Bytes

Contents

module Rapporteur
  # A customization of the default Rails ActionController::Responder.
  # Primarily, this is used to smooth out the differences between Rails
  # responder versions and allow for error messages in GET requests.
  #
  class Responder < ActionController::Responder
    # Internal: Overrides the default behavior by ignoring the HTTP verb and
    # always responding with errors if the rendering resource contains errors.
    #
    def to_format
      if has_errors?
        display_errors
      else
        super
      end
    end


    protected


    if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1
      def display_errors
        controller.render format => {errors: resource.errors}, status: :internal_server_error
      end
    elsif Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 2
      def display_errors
        controller.render format => resource_errors, status: :internal_server_error
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rapporteur-2.0.1 lib/rapporteur/responder.rb
rapporteur-2.0.0 lib/rapporteur/responder.rb
rapporteur-1.1.0 lib/rapporteur/responder.rb
rapporteur-1.0.1 lib/rapporteur/responder.rb
rapporteur-1.0.0 lib/rapporteur/responder.rb