class JbuilderTemplate
def partial!(*args)
json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true
json.array! @posts, partial: "posts/post", as: :post, cached: true
Example:
effectively using the multi fetch feature.
Aside from that, the `:cached` options is available on Rails >= 6.0. This will cache the rendered results
json.comments @post.comments, partial: 'comments/comment', as: :comment
# or:
json.partial! partial: 'posts/post', collection: @posts, as: :post
# or:
json.partial! 'posts/post', collection: @posts, as: :post
# or:
json.array! @posts, partial: 'posts/post', as: :post
Example:
There are multiple ways to generate a collection of elements as JSON, as ilustrated below:
json.partial! 'comments/comments', comments: @message.comments
Example:
comments, which can be used inside the partial.
the file `views/comments/_comments.json.jbuilder`, and set a local variable comments with all this message's
Generates JSON using the template specified with the `:partial` option. For example, the code below will render
def partial!(*args) if args.one? && _is_active_model?(args.first) _render_active_model_partial args.first else options = args.extract_options!.dup options[:partial] = args.first if args.present? _render_partial_with_options options end end