I had a quick question about rendering a ViewComponent (or something that responds to render_in) using the Turbo::Streams::TagBuilder helper. From what I can tell, this should be valid code:
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.prepend(:add_new_user, template: NotificationComponent.new(type: :warning, content: "Email in use"))
end
end
From my understanding, this should return the NotificationComponent’s markup from render_in as the the content of <template>. Instead I’m seeing the class inspect output when this is prepended: <notificationcomponent:0x00007fe5eca77d60></notificationcomponent:0x00007fe5eca77d60>.
I’ve tried different keywords and for now have settled on creating a partial that renders this Component and using that. My question is am I missing something obvious here that allows you to render a component directly, or is there room to add a new component rendering keyword that can support this behavior in turbo-rails?
That was the solution that I ended up going with for now. I might dabble and see if I can get a more direct way to render it without having to use a template file.
Probably so, I’m new to both ViewComponents and Turbo ( obviously ). I was thinking that, since frames lend themselves to partial content by design, it might be cool to have a more streamlined API for rendering a component. I’m using the inline approach now and it’s working for my purposes.
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.prepend(:add_new_user, render_to_string(NotificationComponent.new(type: :warning, content: "Email in use")))
end
end
What is the best practice for broadcasting a turbo update from inside a model using a ViewComponent? I’ve tried a few different ways but can’t seem to get it to work.