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

autumnwolf · December 22, 2014 · 1233 hits

如题,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
No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.