rails / jbuilder

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

ActionView 7.0.7 collection caching breaking on jbuilder arrays #551

Closed morgangrubb closed 1 year ago

morgangrubb commented 1 year ago

ActionView 7.0.7 now expects the rendered object to respond to to_str for caching.

See https://github.com/rails/rails/pull/48645 / https://github.com/rails/rails/pull/48645/files#diff-3ab26da9762a8bb0310c1e11a230ce1d82d95868ed0c28f6b795b5f3e2b61f3eR99

Depending on how a collection is rendered in jbuilder, this may or may not work.

This errors in ActionView 7.0.7 (worked in ActionView 7.0.6 and earlier):

json.posts do
  json.array! @posts, partial: "posts/post", as: :post, cached: true
end

This works in ActionView 7.0.7:

json.posts do
  json.partial! "posts/post", collection: @posts, as: :post, cached: true
end

I'm not sure if this should be considered an issue in jbuilder or ActionView?

javinto commented 1 year ago

I registered this one under https://github.com/rails/rails/issues/48979

morgangrubb commented 1 year ago

Fixed in https://github.com/rails/rails/pull/48937 (7-0-stable or wait for the next 7.0.x release)