2

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: {
       url: request.original_url,
       status: 200,
       errors: {
       } }}
 end

but this code adds request node to each object from collection, while i want this node to be rendered once above collection node. Is there any way to achieve that?

Upperstage
  • 3,747
  • 8
  • 44
  • 67
Avdept
  • 2,261
  • 2
  • 26
  • 48

1 Answers1

3

Here you go.

object false
node :request do
  {
    request: {
      url: request.original_url,
      status: 200,
      errors: { }
    }
  }
end

child(@collection => :response) do
  attributes :id, :submitted_at, :address, :name, :data
end

This should do the trick. object false directive is what puts the node at the root level.

San
  • 1,954
  • 1
  • 14
  • 18