ruby on rails - wrong child root name in rabl and can't set child root name -
i have following rabl code generate json data.
object @event attributes :id, :eid, :name, :address, :description, :latitude, :longitude, :time, :created_at node(:rsvp_count) { |event| event.rsvp_users.count } node(:check_in_count) { |event| event.checkedin_users.count } node(:fid) { |event| event.creater.fid if event.creater} child :rsvp_users, :object_root => false extends 'users/index' end child :checkedin_users, :object_root => false extends 'users/index' end
and data generates looks this:
[ { "event": { "id": 2, "eid": 123458, "name": "event no.2", "address": "189 elm st", "description": "awesome event", "latitude": 10, "longitude": 10, "time": "2013-10-20t18:00:00z", "created_at": "2013-08-15t21:06:21z", "rsvp_count": 3, "check_in_count": 0, "fid": 12345678, "users": [ { "id": 4, "fid": 112233445, "name": "name1", "using_app": true }, { "id": 3, "fid": 9999, "name": "name2", "using_app": false }, { "id": 2, "fid": 123456789, "name": "name3-robot", "using_app": true } ], "checkedin_users": [] } } ]
you can ignore event
hash, weird stuff happening @ bottom in 2 users
array.
so can see, child rsvp_users
array showing name users
if set root
param "rsvp_users"
. however, checkedin_users
array (which empty right now), don't need anything, , it's name automatically checkedin_users
. happening here? bug in rabl? or missing?
i've encountered same exact bug, problem seems setting object_root false. following comment of bigxiang have experimented bit , found works fantastically:
child( {:rsvp => :rsvp}, {:object_root => false} ) extends "users/index" end
note both round parentheses "()" , braces "{}".
Comments
Post a Comment