rails / jbuilder

Jbuilder: generate JSON objects with a Builder-style DSL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ActionView::MissingTemplate after upgrading to Rails 7

mr-romeijn opened this issue · comments

Hello,

I'm encountering an issue with jbuilder after upgrading to Rails 7. Albeit a strange one.

Pinned jbuilder on 2.11.5

Rendering jbuilder files with format :json from within controllers works fine.
Rendering jbuilder files from within .slim templates does not. I'm using Vue and to populate props I render jbuilder views inline and pass it in as component prop.

Example:

<component
  :prop=render(template: 'layers/index.json',
                         locals: {layers: @layers},
                         layout: false)
/>

Above code results in an ActionView::MissingTemplate exception while the file definitely exists as I can actually render the given jbuilder file from within a controller and on top of that above example works under rails 6.

I've been looking into some config options / load ordering which would be able to cause this but haven't been able to find anything. Any suggestions?

Hey, I think this is because "rendering templates with a '.'" got removed in Rails 7:
See rails/rails#39164

You probably need to do something like:

<component
  :prop=render(template: 'layers/index',
                         formats: [:json],
                         locals: {layers: @layers},
                         layout: false)
/>

Hey, I think this is because "rendering templates with a '.'" got removed in Rails 7: See rails/rails#39164

You probably need to do something like:

<component
  :prop=render(template: 'layers/index',
                         formats: [:json],
                         locals: {layers: @layers},
                         layout: false)
/>

That was it! Thanks a bunch 😁. Should've read the deprecation notices better

Great! 😀