Sha256: 58dd3739c41eeedae1edc02b0ae8d0c31159be5fe5bea2b0f4e1d0a4620b9fc0

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

module Tuning
  module ActionController
    module Base
      extend ActiveSupport::Concern

      included do
        rescue_from Exception, with: :error if Rails.env.development?
      end

      protected

      def error(exception=nil)
        if exception
          logger.error exception.message
          exception.backtrace.each { |line| logger.error line }
        end
        respond_to do |format|
          format.xml { head 500 }
          format.json { head 500 }
          format.any { render file: Rails.root.join('public', '500.html'), status: 500, layout: false }
        end
      end

      def not_found
        respond_to do |format|
          format.xml { head 404 }
          format.json { head 404 }
          format.any { render file: Rails.root.join('public', '404.html'), status: 404, layout: false }
        end
      end

      def unauthorized
        respond_to do |format|
          format.xml { head 401 }
          format.json { head 401 }
          format.any { render file: Rails.root.join('public', '422.html'), status: 401, layout: false }
        end
      end

      def forbidden
        respond_to do |format|
          format.xml { head 403 }
          format.json { head 403 }
          format.any { render file: Rails.root.join('public', '422.html'), status: 403, layout: false }
        end
      end

      def unprocessable_entity
        respond_to do |format|
          format.xml { head 422 }
          format.json { head 422 }
          format.any { render file: Rails.root.join('public', '422.html'), status: 422, layout: false }
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tuning-0.2.4 lib/tuning/action_controller/base.rb