我很想使用,render :json但似乎不那么灵活。什么是正确的方法?
render :json
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
我已经使用做了类似的操作render :json。这对我有用:
respond_to do |format| format.html # index.html.erb format.json { render :json => @things.to_json(:include => { :photos => { :only => [:id, :url] } }) } end