ruby on rails - Inlined array elements with JBuilder -


how create array elements in using jbuilder without setting variable first?

i want end following while using jbuilder

{   "something": [     { "name": "first", "foo": "bar"},     { "name": "second", "foo": "baz"}   ] } 

the method have found works following.

json.something   = [     { name: 'first', foo: 'bar' },     { name: 'second', foo: 'baz' }   ]   json.array! |item|     json.(item, :name, :foo)   end end 

is there way make more this?

json.array! 'something'   json.array     json.name 'first'     json.foo 'bar'   end   json.array     json.name 'second'     json.foo 'baz'   end end 

the thing similar can imagine use hardcoded hash:

json.something    json.array! [      {name:'first',foo:'bar'},      {name:'second',foo:'baz'}    ] end 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -