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

Rails Rabl - Custom array keys

I'm trying to customize my RABL API response. I have a collection of games, and each game contains multiple players. For now my players are stored in an array, but I need to access them by a key so I'd like to customize my json response. Here is my…
alskaa
  • 394
  • 1
  • 3
  • 14
2
votes
1 answer

How can i generate json response from rabl gem and money gem with the database table i have?

This is the json i want to build from rabl gem [ "M-0": {"revenue":"value", "fee":"value", "created":"count", "paid":"count", "partially_paid":"count"}, "M-1": {"revenue":"value", "fee":"value", "created":"count", "paid":"count",…
syam
  • 892
  • 8
  • 19
2
votes
1 answer

How to render a RABL template in a view template?

I am using RABL for formatting a JSON API response. However, I would like to use that same JSON and render it inline in a different view to use with some JavaScript. Essentially, I'd like to do: var my_model_data = #{@model.to_json} ...but use the…
Andrew
  • 227,796
  • 193
  • 515
  • 708
2
votes
1 answer

How to get the integer value from enumerize inside a rabl template?

I have the follow model using enumerize gem: class Event < ActiveRecord::Base extend Enumerize enumerize :code, in: {dummy: 0, none: 1, panic: 2 } end This rabl file returns the strings "dummy", "none" and "panic: object @event attributes…
Ricardo
  • 667
  • 9
  • 25
2
votes
1 answer

add data to root hash with RABL

I'd like to add request info to response from RABL my code looks like object @collection => :response attributes :id, :submitted_at, :address, :name, :data rest_of_code_omitted I've tried to add node(:request, :object_root =>true ) do {request:…
Avdept
  • 2,261
  • 2
  • 26
  • 48
2
votes
2 answers

Adding custom key-value pair in json output Grape and Rabl

I am building an API with Rails. The gems I use to build api are Grape and Rabl. I have done a lot of work but now I have to add status flag before all the json response from the api. How could I do this? I have this .rabl file. object…
mgs
  • 404
  • 4
  • 15
2
votes
1 answer

Returning 2 collections in RABL?

I'm trying to return 2 collections in RABL. But I'm having some trouble. What happens is it only returns the second collection when I run it. Here is the function for the index page the rabl is rendering: def index @friends =…
jckly
  • 831
  • 1
  • 11
  • 22
2
votes
3 answers

How to reuse RABL partial templates by keeping conventions?

I am using Ruby on Rails 4 and the RABL gem. I would like to reuse templates by rendering the show.json.rabl view from the index.json.rabl and keep convention stated at jsonapi.org (source: RABL documentation). That is, I have the following files: #…
Backo
  • 18,291
  • 27
  • 103
  • 170
2
votes
1 answer

why won't rails find rabl templates?

working on an api, using the rails-api and rabl gems, basing understanding off railscasts 348 and 322 currently getting Missing template activities/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw,…
John
  • 1,246
  • 15
  • 34
2
votes
1 answer

Rails - Use params[] in rabl file

I have a model named Location that uses Geocoder to retrieve the address from the coordinates when it is created. Then I have an Android app that asks the controller for the list of locations around a particular point in the index method of my…
jbihan
  • 3,053
  • 2
  • 24
  • 34
2
votes
1 answer

RABL with jquery Datatables

In my rails app I am using RABL and on the front end I'm using jquery datatables to view lists of data (actually using angular with a datatable directive). I'm trying to implement server side pagination which calls for a slightly different return…
Arthur Frankel
  • 4,695
  • 6
  • 35
  • 56
2
votes
2 answers

Removing empty hashes in Rabl

In rabl I'm trying to have a child whose elements are conditional, but in the cases where to condition evaluates false it's still rendering elements which have no attributes. Here's my .rabl: child(:products) do attribute :id, :if => lambda{ |p|…
Michael Gruber
  • 601
  • 2
  • 11
  • 24
2
votes
1 answer

How can I set a "root node" for rabl template?

I am building a Rails 3.2 app and I am using Rabl templates. I would like to add a "root node" that displays the total number of records. The solution below adds the total node to each record. I want it on top of all records. collection…
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175
2
votes
1 answer

Rails rabl condition for class variable in view

In controller i have such code: @bank_exchangers = ExchangerList.find(:all, :conditions => {:bank_id => params[:id]}) @currency_list = CurrencyList.all @currencies = [] @currency_list.each do |c| @currencies <<…
Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47
2
votes
2 answers

How to add parent attributes inside its children in rabl template (when parent is an array)?

How to add parent attributes inside its children in rabl template? To do something like this: some_root_attr: { attr_a: 'rgtr', parent: [ { attr_1: 'asd', child: { attr_3: 6, …
Jonas
  • 4,683
  • 4
  • 45
  • 81