instance method
partial!
Ruby on Rails 2.12.0
Since v2.4.1 Last seen in v2.14.1Signature
partial!(*args)
Generates JSON using the template specified with the :partial option. For example, the code below will render the file views/comments/_comments.json.jbuilder, and set a local variable comments with all this message’s comments, which can be used inside the partial.
Example:
json.partial! 'comments/comments', comments: @message.comments
There are multiple ways to generate a collection of elements as JSON, as ilustrated below:
Example:
json.array! @posts, partial: 'posts/post', as: :post # or: json.partial! 'posts/post', collection: @posts, as: :post # or: json.partial! partial: 'posts/post', collection: @posts, as: :post # or: json.comments @post.comments, partial: 'comments/comment', as: :comment
Aside from that, the :cached options is available on Rails >= 6.0. This will cache the rendered results effectively using the multi fetch feature.
Example:
json.array! @posts, partial: "posts/post", as: :post, cached: true json.comments @post.comments, partial: "comments/comment", as: :comment, cached: true
Parameters
-
argsrest
Source
# File lib/jbuilder/jbuilder_template.rb, line 51
def partial!(*args)
if args.one? && _is_active_model?(args.first)
_render_active_model_partial args.first
else
_render_explicit_partial(*args)
end
end
Defined in lib/jbuilder/jbuilder_template.rb line 51
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in JbuilderTemplate