Rails 3.2.12を使用しています。
というモデルAとテーブルがありますa。a_detailsのタイプに基づいた一連の属性であるタグを付ける必要がありますA。のテーブルはありませんa_details。その場で作られています。show メソッドではメソッドを呼び出してgetAdetailsおり、応答では両方を JSON オブジェクトとして渡していAますA_details。
index多くのメソッドがあり、配列オブジェクトを作成してレンダリングするためにそれぞれをループしたいとは思わないので、これはメソッドでトリッキーになります。テーブルレスモデルを考えていactiverecord_associationて、メソッドを使っ:includeてJSONにレンダリングするというgemを使っていました。私は考えていました、これを行うより良い方法はありますか?
# show method.
a = A.new
@a_detail = @a.getADetails
response = {:notification => @a.as_json(:include => :creator), :a_detail => @a_detail}
#index
respond_to do |format|
format.html # index.html.erb
format.json { render json: @objects.as_json(:include => :creator) }
end