Method: Flame::Dispatcher#halt

Defined in:
lib/flame/dispatcher.rb

#halt(new_status = nil, new_body = nil, new_headers = {}) ⇒ Object

Interrupt the execution of route, and set new optional data

(otherwise using existing)

Examples:

Halt, no change status or body

halt

Halt with 500, no change body

halt 500

Halt with 404, render template

halt 404, render('errors/404')

Halt with 200, set new headers

halt 200, 'Cats!', 'Content-Type' => 'animal/cat'

Parameters:

  • new_status (Integer, nil) (defaults to: nil)

    set new HTTP status code

  • new_body (String, nil) (defaults to: nil)

    set new body

  • new_headers (Hash, nil) (defaults to: {})

    merge new headers



121
122
123
124
125
126
# File 'lib/flame/dispatcher.rb', line 121

def halt(new_status = nil, new_body = nil, new_headers = {})
  status new_status if new_status
  body new_body || (default_body_of_nearest_route if body.empty?)
  response.headers.merge!(new_headers)
  throw :halt
end