Module: Glimpse::Rails::ControllerMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/glimpse/rails/railtie.rb

Overview

Overrides ActionController::Base#dispatch to inject glimpse/results before the end body tag. This evaluates the results partial within a controller context for #glimpse_enabled? and other helper methods unavailable in regular middleware.

Instance Method Summary collapse

Instance Method Details

#dispatch(name, request) ⇒ Object

:nodoc:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/glimpse/rails/railtie.rb', line 10

def dispatch(name, request) #:nodoc:
  output = super

  # render_to_string is overridden after the body is closed. Call raw
  # render_to_body here. See
  # ActionController::Metal::Rendering#render_to_string
  glimpse_results = render_to_body(:partial => 'glimpse/results')

  # TODO: gsub! doesn't work. Seems really inefficient to regex replace
  # the whole body
  new_body = output.last.body.gsub(/<\/body>/i,  "#{glimpse_results}</body>")
  output.last.body = new_body

  output
end