Permalink
Browse files

Merge pull request #17 from anithri/master

Update README.md file with short example of #array!
  • Loading branch information...
2 parents 5323856 + 9942e48 commit 133978484a54999fa459504a287224d893441e8e @dhh dhh committed Mar 23, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 README.md
View
@@ -55,6 +55,17 @@ This will build the following structure:
}
```
+Top level arrays can be handled directly. Useful for index and other collection actions.
+
+``` ruby
+#@people = People.all
+json.array!(@people) do |json, person|
+ json.name person.name
+ json.age calculate_age(person.birthday)
+end
+# [ { "name": David", "age": 32 }, { "name": Jamie", "age": 31 } ]
+```
+
You can either use Jbuilder stand-alone or directly as an ActionView template language. When required in Rails, you can create views ala show.json.jbuilder (the json is already yielded):
``` ruby

0 comments on commit 1339784

Please sign in to comment.