mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
2b6d2d2037
This commit keeps a stack of lookup contexts on the ActionView::Base instance. If a format is passed to render, we instantiate a new lookup context and push it on the stack, that way any child calls to "render" will use the same format information as the parent. This also isolates "sibling" calls to render (multiple calls to render in the same template). Fixes #35222 #34138
56 lines
1.2 KiB
Ruby
56 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "pp"
|
|
|
|
require "action_view"
|
|
require "action_view/base"
|
|
|
|
module ActionDispatch
|
|
class DebugView < ActionView::Base # :nodoc:
|
|
RESCUES_TEMPLATE_PATH = File.expand_path("templates", __dir__)
|
|
|
|
def initialize(assigns)
|
|
paths = [RESCUES_TEMPLATE_PATH]
|
|
lookup_context = ActionView::LookupContext.new(paths)
|
|
super(lookup_context, assigns)
|
|
end
|
|
|
|
def compiled_method_container
|
|
self.class
|
|
end
|
|
|
|
def debug_params(params)
|
|
clean_params = params.clone
|
|
clean_params.delete("action")
|
|
clean_params.delete("controller")
|
|
|
|
if clean_params.empty?
|
|
"None"
|
|
else
|
|
PP.pp(clean_params, +"", 200)
|
|
end
|
|
end
|
|
|
|
def debug_headers(headers)
|
|
if headers.present?
|
|
headers.inspect.gsub(",", ",\n")
|
|
else
|
|
"None"
|
|
end
|
|
end
|
|
|
|
def debug_hash(object)
|
|
object.to_hash.sort_by { |k, _| k.to_s }.map { |k, v| "#{k}: #{v.inspect rescue $!.message}" }.join("\n")
|
|
end
|
|
|
|
def render(*)
|
|
logger = ActionView::Base.logger
|
|
|
|
if logger && logger.respond_to?(:silence)
|
|
logger.silence { super }
|
|
else
|
|
super
|
|
end
|
|
end
|
|
end
|
|
end
|