rails jbuilder getting Called id for nil -
i'm trying utilize jbuilder gem format json output.
controller
class locationscontroller < applicationcontroller def tree @locations = location.all end
tree.json.jbuilder
jbuilder.encode |json| json.id @location.id json.name @location.name end
test using url:
http://localhost:5000/locations/tree.json
results:
called id nil, mistakenly 4 -- if wanted id of nil, utilize object_id extracted source (around line #2): 1: jbuilder.encode |json| 2: json.id @location.id 3: json.name @location.name 4: end
you don't seem define @location
in code have posted. should iterate on locations, jbuilder lets illustration this:
jbuilder.encode |json| json.locations @locations |location| json.id location.id json.name location.name end end
see docs if want flat array instead.
ruby-on-rails-3 jbuilder
No comments:
Post a Comment