Module: Otpor::JsonResponse

Extended by:
ActiveSupport::Concern
Defined in:
lib/otpor/json_response.rb

Instance Method Summary collapse

Instance Method Details

#default_render(*args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/otpor/json_response.rb', line 13

def default_render(*args)
  super and return unless request.format.json?

  @errors ||= RequestStore.store[:errors] || nil
  @notes ||= nil

  @status_symbol = RequestStore.store[:status_symbol] if RequestStore.store[:status_symbol]
  @status_code = Rack::Utils::SYMBOL_TO_STATUS_CODE[@status_symbol] if @status_symbol
  @status_code ||= response.status
  @status = {
    name: http_status_name(@status_code),
    code: @status_code,
    type: http_status_type(@status_code)
  }

  partial_exists = lookup_context.exists?("#{controller_path}/#{action_name}", [], true)

  @data_partial ||= "#{controller_path}/#{action_name}" if @status[:type].eql?("Success") && partial_exists

  @instance_variables = capture_new_instance_variables

  @meta ||= infer_meta

  render template: "shared/response", formats: :json, status: @status_code
end

#handle_missing_partialObject



11
# File 'lib/otpor/json_response.rb', line 11

def handle_missing_partial; end