2011-08-15 43 views
1

我有树模型:旅游,巴士和地点 旅游有更多的巴士,巴士更多的位置。在一个json对象中导轨两个对象

我想返回json对象与巴士最后的地点一些旅游。

伪例如:

BUSES 

    BUS1 
     last_location 
    /BUS1 

    BUS2 
     last_location 
    /BUS2 

    BUS3 
     last_locaiton 
    /BUS3 

    /BUSES 

tour.buses会给我大客车巡演,并bus.locations.last最新的位置。

我知道这是没有自小说,但我不知道如何打包在一个json对象来返回它:

回答

1

你可以做这样的:

both_pieces = { 
    :tour   => tour, 
    :last_location => bus.locations.last 
} 

,然后发送both_pieces追溯到J​​SON。然后,客户端将获得一个JSON对象,其中包含tourlast_location对象。