FAQ Database Discussion Community


rails: jbuilder returns an array of 1 json instead of a json object

ruby-on-rails,jbuilder
I have the following simple jbuilder template # temp.jbuilder json.home_id command[:home_id] json.query command[:query] json.query_param command[:query_param] When I x = render "temp", format: :json, locals: { command: { home_id: 0, query: "QQQ", query_param: "P" } } I always get an array in x, instead of getting a json object. Can you...

CarrierWave causing json output to become nested on photo key

ruby-on-rails,ruby,json,carrierwave,jbuilder
I have a weird issue with CarrierWave that I can't find anywhere else. I'm using Jbuilder to generate the JSON for my API. I have a photos table and a url field on the table. Without mount_uploader :url PhotoUploader on the photos model, my JSON looks like this: "photos": [...

Rails: Tweaking attribute of single object served through jbuilder

ruby-on-rails,jbuilder
I am making an API that serves week-calendars (Monday through Sunday) in JSON format. Right now each week-calendar has the attributes 'name' (string), 'start_date' (time object, referring to the Monday on which the calendar starts). I am trying to use the jbuilder gem that comes with Rails. Problem: 1) Calendars...

Checking values of hash before show in jbuider , Ruby on Rails

ruby-on-rails,ruby,jbuilder
I have a jbuilder to show my object. Thats how it looks (part of it) o = @property_object json.features o.property_object_feature_pack, :pool, :garage, terrace and this showing me next: { features: { pool: { params: null, present: "false" }, garage_parking: { params: null, present: "false" }, terrace_balcony: { params: null, present:...

rails 3.2 with jbuilder swallowing errors, instead rendering missing partial

ruby-on-rails,json,jbuilder
I'm using Rails 3.2.21 with JBuilder. I have an example where I'm using an a JBuilder partial inside of a js.erb file to pre populate some fields: var orderData = <%= raw render :partial => 'orders/orders', formats: [:json], handlers: [:jbuilder], locals: {orders: @orders} %>; I have a weird problem where...

Why would I use jbuilder instead of a hash?

ruby-on-rails,json,jbuilder
Say I was making a little app that would echo out whatever string you gave it in a little json object like this: { message: "<Your string>" } What advantages is there is using Jbuilder for something like this versus simply converting a hash into json with to_json?...

Using a referenced model object in JBuilder Ruby on Rails

ruby-on-rails,ruby,json,ruby-on-rails-4,jbuilder
I am trying to learn Ruby on Rails and have come stuck in trying to get a slightly more complex JSON response than from the tutorials I have been following. I have two models as follows: class Worker < ActiveRecord::Base has_many :tips end and class Tip < ActiveRecord::Base belongs_to :worker...