渲染轨道对象



我有一个对象@user作为关于CCD_ 2和CCD_如何在json中呈现整个@user对象。或者如何在视图中渲染它。如果我执行render json: @user,它只显示用户详细信息。如果我执行render @user.account,它将显示帐户详细信息。但是我如何同时渲染这两个

好的,我拿到了

render :json => @user, :methods => [:account, :address, :role]

试试这个:

render :json => @user.to_json(:include => {:acount, :address})

也许你可以试试这个

infos = []
@user.reflections.keys.each do |key|
  infos << @user.public_send(key).inspect
end
return render :text => infos.inspect // display all in browser

我得到了我的解决方案,它是render :json => @user, :methods => [:account, :address, :role]

最新更新