2015-01-06 40 views
2

我運行一個Rails 4.2 - 0.9 AMS的應用程序,和我有(用於說明目的)3種型號:Foo HAS_ONE Bar,的has_many Baz ES。我只在響應中獲得ID,而不是側裝項目。有沒有配置選項,或者我錯過了什麼?::加載ActiveModel串行器嵌入:IDS,包括:真不是側面加載數據

我AMS類是:

class FooSerializer < ActiveModel::Serializer 
    embed :ids, include: true 
    has_one :bar, key: :bar ## For ember-data; it doesn't like "_id" 
    has_many :bazes, key: :bazes 

    attributes :id, :etc 

end 

整個StackOverflow上有是在AMS相當多的話題,我在發佈前看了很多,但是這個剛剛離開我完全難倒。

回答

1

一堆試驗後,我只好打電話給在控制器中的以下內容:

format.json { render json: ActiveModel::ArraySerializer.new(@foos, each_serializer: FooSerializer), root: :foos } 

root: :foos(順便說一句,甚至沒有「真正」的工作,也沒有在串行本身self.root = trueself.root = :foos)是關鍵的一點。

相關問題