def list
@rings = Ring.order("RAND()")
#JSON RENDERING
render :json => @rings.to_json(:include => [:variations, :stones]), :callback => params[:callback]
end
def show
@showring = Ring.includes(:stones, :variations).find(params[:id])
@other_rings = Ring.select([:id, :stone_count]).where(:style_number => @showring.style_number).reject{ |ring| ring == @showring}
#JSON RENDERING
render :json => {@showring.to_json(:include =>[:variations, :stones]), :other_rings => @other_rings}, :callback => params[:callback]
end
リスト ビューのレンダリングは正常に動作しますが、2 つのオブジェクトを使用してビューを表示したい場合、インクルードを使用して表示すると適切な JSON がレンダリングされません。オブジェクト内のすべてをインクルードで引用しています...
JSON 出力は次のようになります。
showring => "{"available":"yes","eng...9","stone_y":"149.4"}]}"
other_rings => 適切にレンダリングされたオブジェクト
別のメモとして、 @rings オブジェクトにインクルードを既に追加している場合、なぜ「to_json」メソッドに関連付けを追加する必要があるのですか?