Skip to content

Commit 844718c

Browse files
authored
Update docs for partials (#39)
1 parent 1bac1c6 commit 844718c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,32 @@ json.posts do
337337
end
338338
```
339339

340-
Usage for rendering partial without assigning it to some key:
340+
Rendering partials without a key is also supported using `json.partial!`, but use
341+
sparingly! `json.partial!` is not optimized for collection rendering and may
342+
cause performance problems. Its best used for things like a shared header or footer.
343+
344+
Do:
345+
346+
```ruby
347+
json.partial! partial: "header", locals: {user: @user} do
348+
end
349+
```
350+
351+
or
341352

342353
```ruby
343-
json.partial! partial: "posts/blog_post", locals: {post: @post} do
354+
json.posts do
355+
json.array! @posts, partial: ["posts/blog_post", locals: {post: @post}] do
356+
end
357+
end
358+
```
359+
360+
Do NOT:
361+
362+
```
363+
@post.each do |post|
364+
json.partial! partial: "post", locals: {post: @post} do
365+
end
344366
end
345367
```
346368

spec/props_template_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require_relative "support/helper"
2+
require_relative "support/rails_helper"
23

34
RSpec.describe "Props::Base" do
45
it "initializes" do

0 commit comments

Comments
 (0)