How to extract values present in array of multiple object's using jbuilder.?
i have an array of multiple objects.
@array1= [ ]
#pushed different types of objects into this array.
if xyz
@array1 << object_type1 # having fields id,f_name
else
@array1 << object_type2 # having fields id,l_name
Now in jbuilder i want
json.array! @array1 do |myarray|
json.id myarray.id
json.name myarray.f_name || myarray.l_name # how to check object type here
end
when i try this it is giving me error like
undefined method `l_name' for #<Object_type1:0xb496eda8>
How to check or tell jbuilder to which objecttype it has to use for name field.?