DEV Community

Discussion on: Setting up a new Rails 7 app with Vite, Inertia, and Svelte

Collapse
 
chmich profile image
Christian Sedlmair • Edited

Thanks, great article.
Had trouble how to access variables from Server, what i missed: i had to export the variable from the javascript, so the code is:

Controller (see: inertia docs)

 def index
    render inertia: 'svelte/index', props: { backend_var: 'Backend' }
 end
Enter fullscreen mode Exit fullscreen mode

Svelte (see: svelte docs)

<svelte:head>
    <title>Hello {backend_var}</title>
</svelte:head>
<script>
    export let backend_var
</script>

Enter fullscreen mode Exit fullscreen mode