我有一个使用此渲染的rails方法:
render :json => @boats, :include => { :mainPhoto => {:only => [:id, :mime]},
:boat_model => { :only => :name, :include => {:boat_type => { :only => :name}}}}
我可以在此响应中包含numTotal变量吗?
答案 0 :(得分:0)
您需要使用as_json
方法在分离的JSON密钥中序列化@boats
:
render :json => { numTotal: boats.size, boats: @boats.as_json(:include => { :mainPhoto => {:only => [:id, :mime]},
:boat_model => { :only => :name, :include => {:boat_type => { :only => :name}}}})