-
Is there any way to render a ViewComponent from outside a controller action? Say, from a background job? ) i guess you could use Oh wait, there's also this weird little-known part of Rails... not sure how/if it can apply to ViewComponents. https://api.rubyonrails.org/classes/ActionController/Renderer.html Has anyone figured out a reasonable way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There is an open issue #1106 where we have been discussing this. |
Beta Was this translation helpful? Give feedback.
Thanks!
I actually think I've gotten it to work as-is with https://api.rubyonrails.org/classes/ActionController/Renderer.html
At least in my simple tests. I don't know if it is helpful if I mention that on #1106. Rails 6.1.
ApplicationController.render(MyViewComponent.new)
Actually seems to work. There is a problem involved if you have devise in your app -- which I think is unrelated to ViewComponent, and is a problem trying to use
AppliationController.render
at all with anything that might accesscurrent_user
. I think it's all a devise/warden issue, that they don't play well with it.Here's the beginning of a kind of horrifying workaround to that...