Skip to content

Support rendering partials from controller renderers#96

Open
seanpdoyle wants to merge 1 commit into
bullet-train-co:mainfrom
seanpdoyle:render-from-controller
Open

Support rendering partials from controller renderers#96
seanpdoyle wants to merge 1 commit into
bullet-train-co:mainfrom
seanpdoyle:render-from-controller

Conversation

@seanpdoyle

Copy link
Copy Markdown
Collaborator

Gems like turbo-rails utilize the
ActionController::Renderer.renderer class method to render templates and partials outside the context of a request-response cycle.

Prior to this bugfix, partials rendered by controller renderers raised errors like the following:

Error:
RendererTest#test_TestController.render_partial_that_declares_helper_methods:
ActionView::Template::Error: undefined method `helpers' for nil:NilClass
    bullet-train-co/nice_partials/test/fixtures/_partial_with_helpers.html.erb:2:in `_fixtures__partial_with_helpers_html_erb__3099800394007487670_4260'

Gems like [turbo-rails][] utilize the
[ActionController::Renderer.renderer][] class method to render templates
and partials outside the context of a request-response cycle.

Prior to this bugfix, partials rendered by controller renderers raised
errors like the following:

```
Error:
RendererTest#test_TestController.render_partial_that_declares_helper_methods:
ActionView::Template::Error: undefined method `helpers' for nil:NilClass
    bullet-train-co/nice_partials/test/fixtures/_partial_with_helpers.html.erb:2:in `_fixtures__partial_with_helpers_html_erb__3099800394007487670_4260'
```

[ActionController::Renderer.renderer]: https://edgeapi.rubyonrails.org/classes/ActionController/Renderer.html#method-i-render
[turbo-rails]: https://github.com/hotwired/turbo-rails/blob/e44b6a98a77a0a2cc927f986a67517d73c4c9246/app/channels/turbo/streams/broadcasts.rb#L87
Comment thread test/renderer_test.rb
end

test "TestController.render partial that declares helper methods" do
TestController.renderer.render partial: "partial_with_helpers" do

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@kaspth currently, this PR is aspirational. This test fails with the stack trace provided in the PR description. I haven't had much success troubleshooting, but I have the sense that it's related to how the monkey patch is (or isn't) being applied to the ActionView::Base instance available to renderer.render calls.

@kaspth

kaspth commented Nov 27, 2023

Copy link
Copy Markdown
Contributor

@seanpdoyle I forgot to say thank you for this! I haven't worked on Nice Partials in a bit, and I don't know when I'll get to this yet. But yeah, it would be cool to fix this 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants