views:

2653

answers:

1

I'd love to use render :json but it seems its not as flexible. Whats the right way to do this?

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @things }

  #This is great
  format.json { render :text => @things.to_json(:include => :photos) }

  #This doesn't include photos
  format.json { render :json => @things, :include => :photos }
end
+7  A: 

I've done something similar with render :json. This is what worked for me:

respond_to do |format|
    format.html # index.html.erb
    format.json  { render :json => @things.to_json(:include => { :photos => { :only => [:id, :url] } }) }
end
Justin Gallagher
Thanks, this helped me out too.
swilliams