render :json 不接受选项 [英] render :json does not accept options
本文介绍了render :json 不接受选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很想使用 render :json
但它似乎没有那么灵活.这样做的正确方法是什么?
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
推荐答案
我用 render :json
做了类似的事情.这对我有用:
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
这篇关于render :json 不接受选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文