One way to do this is to create a hash with the objects you want to render, and then pass this to the rendering method. For example:
respond_to do |format| format.json { render :json => {:moulding => @moulding, :material_costs => @material_costs }} end
If the models are not connected by an active recording, this is probably the best solution.
If an association exists, you can pass the :include
argument to a render call, for example:
respond_to do |format| format.json { render :json => @moulding.to_json(:include => [:material_costs])} end
Note that you will not need to extract the @material_costs
variable in the above section, if you take this approach, Rails will automatically load it from the @moulding
variable.
Ryan Brunner Nov 30 '10 at 21:48 2010-11-30 21:48
source share