1

I'd like to create JSON like this:

{
  "field1": "value-1",
  "field2": "value-2",
  "actions": {
    "edit": "/edit/action/url"
  }
}

using rabl. It doesn't work with child method nor i can't do it with node - got unknown method error. So, is it possible to create custom child node using rabl template? Say something like this:

collection @datas => :datas
attributes :field1, :field2
child :actions do
  node :edit do
    edit_datas_path :id
  end
end

edit
I choose this one:

node :actions do
  actions = {}
  actions[:edit] = edit_customer_group_path(:id)
  node :foo do
    foos = {}
    foos[:bar] = "hello"
    foos
  end
  actions
end

But accepted answer below is correct too.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
NilColor
  • 3,462
  • 3
  • 30
  • 44

1 Answers1

13

I just stumbled across this issue the other day. This ticket in RABL issues helped me. In your case, I was able to generate proper JSON using:

collection @datas
extends "datas/base"
node :actions do
  {:edit => root_path}
end

generated JSON:

{
  id: 1,
  actions: {
            edit: "/"
           }
}

Using RABL 0.5.3

Simon Bagreev
  • 2,879
  • 1
  • 23
  • 24