Questions tagged [rabl]

RABL (Ruby API Builder Language) is a Ruby templating system for generating XML and JSON.

RABL (Ruby API Builder Language) is a Ruby templating system for generating XML and JSON.

294 questions
3
votes
1 answer

Rails api-only ignoring rabl files

I have what I believe to be a very simple app, with Rails 5 (API only) but for some reason it is returning an empty response while it should be returning a json object (using RABL) class ExercisesController < ApplicationController before_action…
Pedro Bernardes
  • 706
  • 1
  • 8
  • 20
3
votes
1 answer

Use decorator in rabl

Does anyone know how to use decorator in rabl file? collection @invitations child(:user) attributes .... I want to be able to do this: collection @invitations child(:user => user.decorate) attributes .... This is working well object…
Thounder
  • 315
  • 2
  • 14
3
votes
1 answer

how to create custom and shared rabl

I have a v1/queues/index.rabl like: collection @queues extends "v1/queues/show" But I want to have a template for successful response which can embed with queue info, like { "ok":true, "data":[@queues' info] (it can be other info too, like…
3
votes
1 answer

Use helper method in JSON with RABL?

I have a simple index.json.rabl file with the following content: collection @calls attributes :time, :destination, :source, :duration I also have a helper method which replaces the source value with a company name: def…
dannymcc
  • 3,744
  • 12
  • 52
  • 85
3
votes
1 answer

Rails JSON API, how to deal with nil object in RABL?

I have a Rails API that I'm using with RABL to send JSON back to the client. I need to have a show and index action for a Question model. In this example, a Question has_many Answers. How do you deal with a nil object in RABL? The API throws an…
jmosesman
  • 716
  • 1
  • 11
  • 24
3
votes
1 answer

JSON - Nesting children RABL or JBuilder for Rails

I have objects that look like: [, , , , ] Where ltree_val…
robbiep
  • 113
  • 1
  • 10
3
votes
1 answer

Spring template engine for rendering JSON

I come from Ruby and have just started testing Spring and find it fairly nice. However i'm used to being able to customize the rendered JSON output with libraries like rabl and it feels really wrong to expose internal models straight out into the…
Andreas
  • 240
  • 3
  • 16
3
votes
2 answers

Formatting Rabl for Ember or Mapping Ember to Rabl?

My rails app used to produce JSON that looked like this: {"paintings": [ {"id":1,"name":"a"}, {"id":2,"name":"b"} ] } I added rabl json formatting, and now the json looks like this: [ {"id":1,"name":"a"}, …
Dan Baker
  • 1,757
  • 3
  • 21
  • 36
3
votes
1 answer

How to use different templates for collection without "root" node with rabl

I'm working with Rabl for a while and just today I faced an interesting problem that I could't solve quite well.. So, I have a collection returned from GET ".../list/512/resources" and here is my sample rabl template that I used to return (without…
mateusmaso
  • 7,843
  • 6
  • 41
  • 54
3
votes
1 answer

Dynamic attribute list rabl

I'm trying to get a json view that uses rabl to have custom attributes sent by the request, so for example if a model has :id, :first_name, :last_name I wanna be able to just call the values I want like say id and first_name only, so what I dont…
merlin371
  • 504
  • 1
  • 4
  • 11
3
votes
1 answer

Fragment caching in a rabl view?

I read rabl caching doc and I don't get how I can cache fragment of code. I have a view like this (there more code, but I removed it for simplicity's sake): object @video attributes :id, :user_id, :event_id child :event do attributes :id …
mr.The
  • 445
  • 5
  • 17
3
votes
2 answers

rabl reusing a template

I have this show.json.rabl for the show action of a controller to render out some JSON in my Rails app, I figure that the edit action's JSON response is no different than my show one, so I wonder if there is a method to use the show.json.rabl for…
Nik So
  • 16,683
  • 21
  • 74
  • 108
3
votes
3 answers

Render RABL partials with polymorphic models

I have a data model where a User can like a Project, Suggestion, Comment, or other objects. The models are set up correctly, and likes/show.rabl works if we were just to support the Project child object @like attributes :id, :created_at,…
netwire
  • 7,108
  • 12
  • 52
  • 86
2
votes
1 answer

Returning child nodes where there is a HABTM association in Rails API using Rabl

I am using the popular Rabl gem for producing a JSON API in Rails. However, I am having some difficulty understanding how to return results of a HABTM association. I have a model called Sale and a model called Merchandise. A HABTM association is…
alpheus
  • 979
  • 6
  • 15
  • 34
2
votes
1 answer

Rails RABL: how to respond with specified http status code?

Basically I have the following controller method: def create begin @check_in = create_check_in() rescue => exception render json: { message: exception }, status: 500 end end and the following json.rabl file: object…