Search code examples
ruby-on-railsjsonruby-on-rails-4jbuilder

Jbuilder: json.variable instead of json.name


I'm using jbuiler to generate api, when I go generate a value, I do:

json.name type.name

I'd like to use the value type.name, for example, to generate the name of the value, this way I could generate an array with the name of my value:

json.type.name do
  json.array categories
end

How can I use a variable instead a static string for the value of my parameter?

Thanks!


Solution

  • you can do

    json.set! type.name do
      json.array categories
    end