Module: Halt

Extended by:
ActiveSupport::Concern
Defined in:
lib/halt.rb,
lib/halt/error.rb,
lib/halt/engine.rb,
lib/halt/version.rb

Overview

An extension to ActionController which enables standard error handling using ActionView and translations.

Examples:

class ApplicationController < ActionController::Base
  include Pundit
  include Halt

  halt ActiveRecord::RecordNotFound, with: :not_found
  halt Pundit::NotAuthorizedError, with: :unauthorized
end

Defined Under Namespace

Classes: Engine, Error

Constant Summary collapse

VERSION =
'1.0.0'.freeze

Instance Method Summary collapse

Instance Method Details

#halt(status, **options) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/halt.rb', line 37

def halt(status, **options)
  @error = Error.new(status, **options)

  respond_to do |format|
    format.html { render 'error', status: @error.status, error: @error }
    format.json { render json: @error, status: @error.status }
  end && return
end