1
私は3つのモデルを持っており、それらをすべて単一オブジェクト内のJSONとして出力しようとしています。次のようにオブジェクトに複数のインクルードを戻すJSON
モデルや団体は、次のとおりです。
class Customer < ApplicationRecord
has_one :subscription
has_one :address
end
class Address < ApplicationRecord
belongs_to :customer
end
class Subscription < ApplicationRecord
belongs_to :customer
end
私は、JSONは以下を使用して関連するすべてのデータを返すようにしようとしています:
class HomeController < ApplicationController
def index
@customers = Customer.all
render json: @customers, :include => :address, :subscription
end
end
しかし、これはどこの構文エラーを返してルビーはどこかで=>
を期待しています。どのように私はこのデータのすべてを出力することができます上の任意の助けが大歓迎です。