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
30
votes
6 answers

Rails 4 - How to render JSON regardless of requested format?

I'd like a Rails controller (all of them, actually, it's an API) to render JSON always always. I don't want Rails to return "route not found", or try and fail to find an HTML template, or return 406. I just want it to automatically and always render…
Zach
  • 1,291
  • 2
  • 13
  • 21
24
votes
4 answers

Removing child root nodes in RABL

I'm trying to render a pretty simple data structure using RABL, but I can't figure out how to remove the child root nodes properly. Here are my two templates. First, the collection index template. collection @groups, :object_root =>…
BBonifield
  • 4,983
  • 19
  • 36
22
votes
2 answers

How to remove html redirection in devise authenticate_user

I use the devise's authenticate_user! method in a controller. This is working fine when the auth_token provided in the request is the correct one but if the authentication fails, I end up with: curl -XGET…
Luc
  • 16,604
  • 34
  • 121
  • 183
20
votes
7 answers

Rendering a simple Ruby hash with RABL

I have a ruby hash that I'd like to render using RABL. The hash looks something like this: @my_hash = { :c => { :d => "e" } } I'm trying to render this with some RABL code: object @my_hash => :some_object attributes :d node(:c) {…
SundayMonday
  • 19,147
  • 29
  • 100
  • 154
12
votes
4 answers

How to paginate Rabl's collections

I have this template: # app/views/posts/index.rabl collection @posts => :posts attributes :id, :title, :subject child(:user) { attributes :full_name } node(:read) { |post| post.read_by?(@user) } Witch returns: { "posts": [ { …
Zag zag..
  • 6,041
  • 6
  • 27
  • 36
8
votes
1 answer

How to inspect errors in rable view files

I am using rabl with rails 3.2 application, I am getting errors in rabl view files but it's not pointing exact error line where error occured. So now I want debug view code for the line causes error, something like puts statement.
ratnakar
  • 352
  • 1
  • 11
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
6
votes
1 answer

how to render a rabl view in a rake task?

I'm trying to render a rabl view to string in a rails 3.2 rake task. I'm rendering it to string in order to send some JSON through Pusher from a background task. I've looked at various render_to_string from rake task answers but none of them seem to…
Marc
  • 3,812
  • 8
  • 37
  • 61
6
votes
3 answers

How to " order by id " JSON with Rabl

I want json output order by id(child id) Can I solve this problem ? this is some code in my project show.json.rabl (I used Rabl) object @book attributes :id , :name child :questions do attributes :id , :name end books_controller.rb def show …
6
votes
1 answer

RABL: JSON objects without root key

I have this rabl template: object @photo attributes :id child :comments do attributes :id, :body end Which gives me this JSON response: { photo: { id: 1, comments: [ { comment: { id: 1, body: 'some…
Calvin
  • 8,697
  • 7
  • 43
  • 51
6
votes
1 answer

Is it possible to do a fragment caching in a rabl view?

I'm trying to do something like this: cache "api/v1/cars_index/#{I18n.locale}/car/#{car.cache_key}" do attributes :id, :brand, :model_name, :fuel, :km, :year, :price node(:color) { |car| car.color.present? ? car.color : '' } end
Niels Kristian
  • 8,661
  • 11
  • 59
  • 117
6
votes
1 answer

Rabl Multi-model collection

I am using RABL to output a Sunspot/SOLR result set and the search results object is composed of multiple model types. Currently within the rabl view I have: object false child @search.results => :results do attribute :id, :resource, :upccode …
ejlevin1
  • 735
  • 5
  • 15
6
votes
1 answer

wrong child root name in rabl and can't set child root name

I have to following rabl code to generate some JSON data. object @event attributes :id, :EID, :name, :address, :description, :latitude, :longitude, :time, :created_at node(:rsvp_count) { |event| event.rsvp_users.count } node(:check_in_count) {…
Enzo
  • 969
  • 1
  • 8
  • 23
6
votes
3 answers

Rabl.render: how to use view helper methods?

I'm using Rabl to generate XML output in a rake task: xml = Rabl.render @listings, 'feeds/listings', :format => :xml # do stuff with xml However, I need to use multiple helper methods in the rabl view file referenced, and I keep getting a…
eirikir
  • 3,802
  • 3
  • 21
  • 39
6
votes
1 answer

undefined method `scan' for {"tooth"=>""}:Hash

I upgraded to rails4 from 3.2.2 and i now get this undefined method from my rabl template that id didn't get before the upgrade. the "tooth" paramater on procedures is a set by a getter/setter method that is stored in the postgres database as a…
mattclar
  • 237
  • 1
  • 3
  • 15
1
2 3
19 20