Closed james-em closed 6 months ago
To render some static ERB, why not:
# projects_controller.rb
def show
render inertia: 'static', props: {
body: render_to_string
}
end
I agree with @buhrmi , this should be possible with current functionality! Closing, but appreciate the thorough writeup!
Indeed it was only to DRY out a bit more the code. Understood! Thanks for taking the time to check it out
I will refer to Svelte in the following text because it's the one I currently use, however it's interchangeable with any supported frontend works such as React, Vue, ...
Goal
Allow to render Svelte page components only when really needed in order to save development cost and time.
Per controller action, it would be great to be able to render static HTML/ERB/Slim/HAML view inside a Svelte component.
Tools such as simple_form can be a life saver when it comes to development speed and this introduce the ability to keep using these powerful librairies and all Rails view engine features
Proposal
Updating the
render inertia: ...
syntax without introducing any breaking changes.How static would work
It would work exactly the same as the current behavior. It would still render the same HTML layout and still render the same HTML/JSON response without any extra HTML tag:
However, the page structure would change just a little
A static svelte component (could be a layout or a view) would be this simple:
Testing
I have written a renderer override to allow testing the idea. Simply put this in an initializer