新手问题 rocket_plant 如何正确返回 has_many 的 json 类型属性

autumnwolf · 2014年12月22日 · 1232 次阅读

如题,show 返回 json 数据: Place Model

has_many :invitees
has_many :address

PlacesViewController

def show
    place = Place.find_by_id(params[:id])
    expose place
 end

Roecet_plants 用 expose 返回所有 place 的属性,我现在要对其进行筛选,如下在 model 的

serializable_hash

方法里面。可是不能正确返回 has_many 的数据,如下,只返回 has_many: address,并切包含所有 Address 的属性,不返回 has_many :invitees 请问如何返回所有 has_many,包括 address 和 invitees

def serializable_hash(options={})
   super only:[:id,:name],
   include:[address:{only:[:id]},invitees:{only: [:id]},]
 end
暂无回复。
需要 登录 后方可回复, 如果你还没有账号请 注册新账号