Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/action_prompt/renderer.rb
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines 3 to +9
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using Rails’ built-in renderer (ApplicationController.renderer)—it’s thread-safe and avoids manually instantiating controllers.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +9
Copy link

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing a single controller instance may introduce state leaks or thread-safety issues under concurrent requests; consider using a fresh renderer per call or a thread-local instance.

Copilot uses AI. Check for mistakes.
end
end
end