Questions tagged [jbuilder]

JBuilder is a IDE for Java developed by Embarcadero Technologies. It is also the name of a Ruby library for producing JSON.

JBuilder is a Java IDE from Embarcadero Technologies. It was originally developed by Borland in 1997, and now belongs to Embarcadero Technologies.

Jbuilder is also the name of a Ruby library that lets you "create JSON structures via a Builder-style DSL".

335 questions
11
votes
1 answer

How can I render one partial twice in jbuilder?

I want to render a jbuilder template like this: json.author do json.partial! 'user', user: @user end json.owner do json.partial! 'user', user: @user end It seems a waste to render one partial twice, can I render like this? user_json =…
Tony Han
  • 2,130
  • 3
  • 24
  • 37
11
votes
7 answers

Rails JSON API layouts with Jbuilder (or other)

In my rails 3.2 app, I'm using jbuilder to render responses from my JSON api. I want to provide a common structure to all API responses, and a layout would be the likely solution to keep my views DRY. ex: I'd like every response to be of the…
MikeL
  • 483
  • 2
  • 6
  • 12
9
votes
2 answers

Generate a nested JSON array in JBuilder

I have this models in ruby on rails Branch model: has_many :menus class Branch < ActiveRecord::Base belongs_to :place belongs_to :city has_many :menus , dependent: :destroy belongs_to :type_place end Menu model: has_many…
FrancoML
  • 95
  • 1
  • 1
  • 4
8
votes
1 answer

Rails 4 how to speed up json rendering

I have 1500 small objects to render for a webservice inside a rails 4 application. I use json as format with jbuilder for templates. I already changed the json engine to oj in the app initializer: require 'oj_mimic_json' #MultiJson.use…
dc10
  • 2,160
  • 6
  • 29
  • 46
8
votes
2 answers

Rails proper way to display error with jbuilder

I am looking to display an error message in a jbuilder view. For instance, one route I might have might be: /foos/:id/bars If :id submitted by the user does not exist or is invalid, I'd like to be able to display the error message accordingly in my…
randombits
  • 47,058
  • 76
  • 251
  • 433
8
votes
1 answer

Using JBuilder to create nested JSON output in rails

I am looking for examples on how to create nested JSON output using JBuilder. I want to create and output similar to this: { "name": "John Doe", "reservations": [ { "restaurant": "ABC", "reservation_time":…
ESoft
  • 852
  • 1
  • 8
  • 21
8
votes
2 answers

Rabl, Jbuilder or manual json build for api?

To build api for a large scale application, which method is better interms of performance, should i use Rabl, Jbuilder or build json objects manually?I am building api /endpoints for mobile apps.
katie
  • 2,921
  • 8
  • 34
  • 51
7
votes
1 answer

Create a JSON having dynamic hash keys with jbuilder

Here I want to output json with dynamic group name rather than word group @tickets.each do |group, v| json.group { json.array! v do |ticket| json.partial! 'tickets/ticket', ticket: ticket end} end Where @ticket is a hash like this…
Adnan Ali
  • 2,890
  • 5
  • 29
  • 50
7
votes
2 answers

Jbuilder not working with gem rails-api

I'am trying rails-api gem with jbuilder and i can't seem to make it work Here is a sample of my rails-api controller / jbuilder views Gemfile gem 'jbuilder' Controller app/controller/users_controller.rb def show @user = User.find_by(id:…
C404
  • 243
  • 4
  • 14
7
votes
2 answers

How do I delegate to a model's to_builder method from a JBuilder view?

Let's say I have a Person class and a Gang class class Person belongs_to :gang attr_accessible :name, :secret def to_builder Jbuilder.new do |app| person.id id person.name name end end end class Gang has_many :people …
Chris Aitchison
  • 4,656
  • 1
  • 27
  • 43
6
votes
4 answers

Is there any way to hide attributes in a Rails Jbuilder template?

I know you can explicitly list fields like so, json.(model, :field_one, :field_two, :field_three) But is there anything similar to the following, json.(model, except: :field_two) which would output all of the model fields except the one called…
sambecker
  • 1,099
  • 12
  • 28
6
votes
2 answers

return unescaped html with jbuilder

I would like to return html content via jbuilder: json.array!(@articles) do |article| json.extract! article, :id, :title, :html_content end But it's returns escaped html: { "id": 2, "title": "", "html_content": "\u003cp\u003e\u003cimg…
Oded Harth
  • 4,367
  • 9
  • 35
  • 62
6
votes
2 answers

Jbuilder Rails caching is slower

I've tried to use caching with collections (with multiple solutions) the problem is that when ever I try caching the response become slower consider the following example of a collection that renders 2 partials for every item in it (around 25…
a14m
  • 7,808
  • 8
  • 50
  • 67
6
votes
1 answer

How to add extra attributes to jbuilder index page

I have been trying to add custom attributes to jbuilder like i do in the show page to my index page for pagination with will paginate and its not displaying the custom attributes. for example what i have in my controller action is def index …
Uchenna
  • 4,059
  • 6
  • 40
  • 73
6
votes
2 answers

Inlined array elements with JBuilder

How do you create an array with elements in it using Jbuilder without setting it to a variable first? I want to end up with the following while using JBuilder { "something": [ { "name": "first", "foo": "bar"}, { "name": "second", "foo":…
Jason
  • 3,736
  • 5
  • 33
  • 40
1
2
3
22 23