rails jbuilder - just an array of strings -
i have controller returns array of activerecord objects , jbuilder view generate json (all standard stuff). works great if want example array of hashes.
so example have:
json.array!(@list) |l| json.( l, :field ) end
which returns
[ { "field": "one" }, { "field": "two" }, { "field": "three" } ]
however, want array of strings; such json is
[ "one", "two", "three" ]
whats should jbuilder file be?
a bit late work:
json.array! @list
but consider use in block create json pair:
json.data json.array! @list end # => { "data" : [ "item1", "item2", "item3" ] }
Comments
Post a Comment