Sha256: 920577d4b6fda680d37f80ca75b85e7a5ccae038e939368a662ee74c5a7b1e9d

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 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)
        logger.error exception.message
        exception.backtrace.each { |line| logger.error line }
        respond_to do |format|
          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.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.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.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.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

2 entries across 2 versions & 1 rubygems

Version Path
tuning-0.1.2 lib/tuning/action_controller/base.rb
tuning-0.1.1 lib/tuning/action_controller/base.rb