一尘不染

render:json不接受选项

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

阅读 297

收藏
2020-07-27

共1个答案

一尘不染

我已经使用做了类似的操作render :json。这对我有用:

respond_to do |format|
    format.html # index.html.erb
    format.json  { render :json => @things.to_json(:include => { :photos => { :only => [:id, :url] } }) }
end
2020-07-27