rails / jbuilder

Jbuilder: generate JSON objects with a Builder-style DSL
MIT License
4.34k stars 440 forks source link

`json.partial!` line in template is not executed when passing locals using new hash syntax #546

Closed shunwen closed 1 year ago

shunwen commented 1 year ago

I have this line in jbuilder template using the new hash syntax. It seems this line is not executed at all.

json.partial! 'comments', post:, comments:

It works if I modify the line back to the old syntax or add braces or brackets.

json.partial!('comments', post:, comments:)
json.partial! 'comments', { post:, comments: }
json.partial! 'comments', post: post, comments: comments

Could anyone help to explain what happens here? Is it something related to the template compilation? Thanks.

shunwen commented 1 year ago

Got an answer here: https://stackoverflow.com/questions/76046278/why-the-json-partial-line-in-jbuiler-template-is-not-executed-when-passing-loca

ivangreene commented 1 year ago

It seems like this should be reopened and fixed as mentioned in the SO answer, i.e adding a semicolon at the end of this line: https://github.com/rails/jbuilder/blob/v2.11.5/lib/jbuilder/jbuilder_template.rb#L277

Especially since Rubocop will suggest removing the hash value if repeated as in the last example