inertiajs / inertia-rails

The Rails adapter for Inertia.js.
https://inertia-rails.dev/
MIT License
574 stars 45 forks source link

render from inside ERB template #101

Closed DeedleFake closed 1 year ago

DeedleFake commented 1 year ago

I have recently switched from WebpackerSvelte to Inertia.js for using Svelte components with a Rails backend, but one feature I don't seem to be able to replicate is the ability to render a Svelte component into the middle of an ERB template. With WebpackerSvelte, I was able to do something like

<%= svelte_component('Name', something: 'value') %>

and it would just work, but inertia-rails doesn't seem to work for that. Am I missing something, or is there no way to do this?

PedroAugustoRamalhoDuarte commented 1 year ago

I don't believe this is achievable with Inertia. Although Inertia allows us to manage the entire page with Svelte, it doesn't provide the capability to handle just a single component inside an erb page

bknoles commented 1 year ago

Yeah, Inertia is meant to replace the Rails view layer, not to integrate within it.

I work in React, and if I needed an ERB template driven application with some interactive sprinkles in it I'd reach for a different solution than Inertia.js.

DeedleFake commented 1 year ago

Ah well. Thankfully, I only need it for some internal pages that aren't user-facing, so I can just keep using `WebpackerSvelte for those, I guess. Just means that they won't get any SSR, but that's fine.

AlvesJorge commented 4 months ago

Only want to comment that I have the same "issue" as @DeedleFake!

Converting an existing Rails + Vue app into one using inertia, some pages aren't just Vue components but ActionView pages with a vue component embedded in them.

As a workaround for those I kept my old createApp configuration but it only runs if it can't find the #app inertia component.

AlvesJorge commented 4 months ago

I'm also curious as to why render inertia is not available in erb