Support rendering partials from controller renderers#96
Open
seanpdoyle wants to merge 1 commit into
Open
Conversation
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
seanpdoyle
commented
Nov 15, 2023
| end | ||
|
|
||
| test "TestController.render partial that declares helper methods" do | ||
| TestController.renderer.render partial: "partial_with_helpers" do |
Collaborator
Author
There was a problem hiding this comment.
@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.
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 😄 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: