Class: Otto::ResponseHandlers::ViewHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/otto/response_handlers/view.rb

Overview

Handler for view/template responses

Class Method Summary collapse

Methods inherited from BaseHandler

ensure_status_set

Class Method Details

.handle(result, response, context = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/otto/response_handlers/view.rb', line 11

def self.handle(result, response, context = {})
  if context[:logic_instance].respond_to?(:view)
    response.body = [context[:logic_instance].view.render]
    response['Content-Type'] = 'text/html' unless response['Content-Type']
  elsif result.respond_to?(:to_s)
    response.body = [result.to_s]
    response['Content-Type'] = 'text/html' unless response['Content-Type']
  else
    response.body = ['']
  end

  ensure_status_set(response, context[:status_code] || 200)
end