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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -