Module: Terrazzo::UsesSuperglue::TemplateLookupOverride
- Included in:
- ApplicationController
- Defined in:
- lib/terrazzo/uses_superglue.rb
Overview
Prepended to fix a template shadowing problem.
When a controller inherits a long view prefix chain (e.g. from Devise or other engines), Superglue’s _render_template calls template_exists? with all those prefixes and may find a gem-supplied HTML template, causing it to render the unstyled ERB instead of the React page. This override restricts the template existence check to the app’s own view path only.
Instance Method Summary collapse
Instance Method Details
#_render_template(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/terrazzo/uses_superglue.rb', line 13 def _render_template( = {}) if @_capture_options_before_render @_capture_options_before_render = false @_render_options = _ensure_react_page!([:template], [:prefixes]) app_views = Rails.root.join("app/views").to_s app_resolver = view_paths.to_a.find { |vp| vp.to_s == app_views && !vp.is_a?(Superglue::Resolver) } prefixes = Array([:prefixes]).compact html_template_exist = app_resolver&.find_all([:template], prefixes, false, { formats: [:html], locale: [], handlers: [], variants: [] }, nil, [])&.any? if !html_template_exist super(.merge(template: _superglue_template, prefixes: [])) else super end else super end end |