Skip to content

Commit 0ef3775

Browse files
author
Robert Mosolgo
committed
Merge pull request #178 from noinkling/noinkling-readme-jbuilder
Readme: clarify Jbuilder root node recommendation
2 parents a05c5af + 2ae957f commit 0ef3775

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ react_component('HelloMessage', render(template: 'messages/show.json.jbuilder',
149149

150150
##### Important Note
151151

152-
By default, the scaffolded Rails index jbuilder templates do not include a root-node. An example scaffolded index.json.jbuilder looks like this:
152+
By default, the scaffolded Rails index Jbuilder templates do not include a root node. An example scaffolded index.json.jbuilder looks like this:
153153

154154
```ruby
155155
json.array!(@messages) do |message|
@@ -164,7 +164,7 @@ which generates JSON like this:
164164
[{"id":1,"name":"hello","url":"http://localhost:3000/messages/1.json"},{"id":2,"name":"hello","url":"http://localhost:3000/messages/2.json"},{"id":3,"name":"hello","url":"http://localhost:3000/messages/3.json"}]
165165
```
166166

167-
This is not suitable for ReactJS props, which is expected to be a key-value object. You will need to wrap your index.json.jbuilder node with a root node, like so:
167+
However ReactJS expects the collection of props provided to a component to be a key-value object. Therefore, if you want to use your Jbuilder templates directly with the helper, you will need to wrap your index.json.jbuilder array with a root node like so:
168168

169169
```ruby
170170
json.messages(@messages) do |message|

0 commit comments

Comments
 (0)