From f1943e28a464da1c59684ac65287bd63b4850ba9 Mon Sep 17 00:00:00 2001 From: Alexander Senko Date: Mon, 9 Jun 2025 12:09:38 +0700 Subject: [PATCH] Optimization: reuse a controller for rendering --- lib/action_prompt/renderer.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/action_prompt/renderer.rb b/lib/action_prompt/renderer.rb index 09d6526..b868562 100644 --- a/lib/action_prompt/renderer.rb +++ b/lib/action_prompt/renderer.rb @@ -1,13 +1,12 @@ module ActionPrompt class Renderer def initialize - # NOOP + @controller = ApplicationController.new + @controller.prepend_view_path(Rails.root.join("app", "prompts")) end def render(template_name, locals: {}) - controller = ApplicationController.new - controller.prepend_view_path(Rails.root.join("app", "prompts")) - controller.render_to_string(template: template_name, locals: locals, layout: false) + @controller.render_to_string(template: template_name, locals: locals, layout: false) end end end