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
52
votes
1 answer

Rails: Render Json Status Problems

When I render json: { error: "No such user; check the submitted email address", status: 400 } and then do my tests and check for response.code I get 200 rather than 400 I'm sure the answer to this absurdly simple, but I've been…
Morgan
  • 1,438
  • 3
  • 17
  • 32
38
votes
1 answer

jbuilder vs rails-api/active_model_serializers for JSON handling in Rails 4

I have started to begin with Rails 4. While working with handling of JSON format data, I found we can use rails/jbuilder and works well. However, When I was taking Codeschool's Rails 4 Pattern, they mentioned gem called active_model_serializers.…
33
votes
2 answers

undefined local variable or method `json' in JBuilder

When I try get all categories (index action) there is an error: undefined local variable or method `json' But in show action everything fine. All files has .jbuilder extension. Here is controller code: def index @categories = Category.all end #…
Meliborn
  • 6,495
  • 6
  • 34
  • 53
32
votes
2 answers

Why is JBuilder not returning a response body in JSON when testing RSPEC

When testing a JSON response from an RSPEC controller test using DHH's JBuilder, my response.body is always "{}". It works fine in development/production modes AND when I use the to_json method instead of jbuilder, I get proper JSON in my…
Kirk
  • 1,521
  • 14
  • 20
30
votes
6 answers

How to extract all attributes with Rails Jbuilder?

It's a pain to write codes like this all the time in jbuilder.json template: json.extract! notification, :id, :user_id, :notice_type, :message, :resource_type, :resource_id, :unread, :created_at, :updated_at So I'd like to code like…
chikaram
  • 700
  • 1
  • 7
  • 18
27
votes
2 answers

rails jbuilder - just an array of strings

i have a controller that returns an array of ActiveRecord objects and a jbuilder view to generate the json (all standard stuff). works great if i want for example an array of hashes. so for example i have: json.array!(@list) do |l| json.( l,…
yee379
  • 6,498
  • 10
  • 56
  • 101
25
votes
8 answers

How could I render to a string a JSON representation of a JBuilder view?

I'm using JBuilder as to return some JSON. I have a index.json.jbuilder that generates the data, and I need to render it to a string. However, I'm not sure how to do this, since: @my_object.to_json and @my_object.as_json don't seem to go through…
Geo
  • 93,257
  • 117
  • 344
  • 520
23
votes
1 answer

Render a JBuilder view in html view

I've created a json view with JBuilder. But I want to preload this into a data object, so Backbone has access to the data early on without fetching for it. How can I render the list.json.jbuilder view into my list.html.erb view? Normally without…
Jareish
  • 772
  • 2
  • 9
  • 24
22
votes
1 answer

JBuilder dynamic keys for model attributes

I'm trying to build a JSON file to access a product's variation via a variation code. Ideally, I could call variations.abcdefgh essentially asking to define a structure like this: { "variations":{ "abcdefgh":{ "available":true, …
zack
  • 397
  • 1
  • 3
  • 10
17
votes
4 answers

Render html partial in JSON JBuilder

I am rendering JSON of some students using JBuilder in Rails 4. I want each student to have a "html" attribute that contains the HTML partial for a given student: [ { html: "I was rendered from a partial" } ] I have tried the…
Kyle Decot
  • 20,715
  • 39
  • 142
  • 263
17
votes
3 answers

JBuilder loop that produces hash

I need loop that produces hash, not an array of objects. I have this: json.service_issues @service.issues do |issue| json.set! issue.id, issue.name end that results: service_issues: [ { 3: "Not delivered" }, { 6: "Broken item" }, …
Jonas
  • 4,683
  • 4
  • 45
  • 81
15
votes
2 answers

Skip jbuilder files when I generate a scaffold?

When I scaffold I don't want it to generate these files: invoke jbuilder create app/views/tests/index.json.jbuilder create app/views/tests/show.json.jbuilder But how? in my application.rb I have this: config.generators do |g| …
12
votes
1 answer

Jbuilder Partial With Path

I am attempting to render a partial jbuilder file using the below json.(@request, :id) json.profile do json.partial! partial: 'users/user_reduced', user: @request.user end the partial is below (users/_user_reduced.json.jbuilder) json.(user,…
steventnorris
  • 5,656
  • 23
  • 93
  • 174
12
votes
3 answers

Rails jbuilder DateTime adding decimals to second

I'm using JBuilder to render the views of the JSON API part of my application. The problem I'm running into is that my DateTimes are being rendered like this: "2013-07-02T17:03:18.000Z" ...when what I really want is this: "2013-07-02T17:03:18Z" I'm…
elsurudo
  • 3,579
  • 2
  • 31
  • 48
11
votes
6 answers

How to use RSpec with JBuilder?

I'm looking for a clean way to use JBuilder and test the json output with RSpec. The popular way for JSON testing is to implement the as_json method, and then in RSpec compare the received object with the object.to_json method. But a large reason…
beeudoublez
  • 1,222
  • 1
  • 12
  • 27
1
2 3
22 23