From 961779997cb28750d52d6186b41c29c33677ae0f Mon Sep 17 00:00:00 2001 From: Sean Collins Date: Wed, 23 Sep 2015 13:57:52 -0600 Subject: Add note about Jbuilder [skip ci] --- guides/source/action_view_overview.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'guides/source/action_view_overview.md') diff --git a/guides/source/action_view_overview.md b/guides/source/action_view_overview.md index 00c41a480e..d3c0a3666f 100644 --- a/guides/source/action_view_overview.md +++ b/guides/source/action_view_overview.md @@ -147,6 +147,39 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do end ``` +#### Jbuilder +Jbuilder is a gem that's +maintained by the Rails team and included in the default Rails Gemfile. +It's similar to Builder, but is used to generate JSON, instead of XML. + +If you don't have it, you can add the following to your Gemfile: + +```ruby +gem 'jbuilder' +``` + +A Jbuilder object named `json` is automatically made available to templates with +a `.jbuilder` extension. + +Here is a basic example: + +```ruby +json.name("Alex") +json.email("alex@example.com") +``` + +would produce: + +```json +{ + "name": "Alex", + "email: "alex@example.com" +} +``` + +See the +Jbuilder documention for more examples and information. + #### Template Caching By default, Rails will compile each template to a method in order to render it. When you alter a template, Rails will check the file's modification time and recompile it in development mode. -- cgit v1.2.3