Skip to content

Commit

Permalink
Update docs for partials (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jho406 authored Nov 21, 2024
1 parent 1bac1c6 commit 844718c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,32 @@ json.posts do
end
```

Usage for rendering partial without assigning it to some key:
Rendering partials without a key is also supported using `json.partial!`, but use
sparingly! `json.partial!` is not optimized for collection rendering and may
cause performance problems. Its best used for things like a shared header or footer.

Do:

```ruby
json.partial! partial: "header", locals: {user: @user} do
end
```

or

```ruby
json.partial! partial: "posts/blog_post", locals: {post: @post} do
json.posts do
json.array! @posts, partial: ["posts/blog_post", locals: {post: @post}] do
end
end
```

Do NOT:

```
@post.each do |post|
json.partial! partial: "post", locals: {post: @post} do
end
end
```

Expand Down
1 change: 1 addition & 0 deletions spec/props_template_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative "support/helper"
require_relative "support/rails_helper"

RSpec.describe "Props::Base" do
it "initializes" do
Expand Down

0 comments on commit 844718c

Please sign in to comment.