def list
@rings = Ring.order("RAND()")
#JSON RENDERING
render :json => @rings.to_json(:include => [:variations, :stones]), :callback => params[:callback]
end
def show
@showring = Ring.includes(:stones, :variations).find(params[:id])
@other_rings = Ring.select([:id, :stone_count]).where(:style_number => @showring.style_number).reject{ |ring| ring == @showring}
#JSON RENDERING
render :json => {@showring.to_json(:include =>[:variations, :stones]), :other_rings => @other_rings}, :callback => params[:callback]
end
我的列表视图渲染工作正常,但是当我想做一个显示视图时,有两个对象,并且显示包含不会呈现正确的 JSON。它引用了对象中的所有内容,包括...
JSON 输出如下所示:
显示 => "{"available":"yes","eng...9","stone_y":"149.4"}]}"
other_rings => 正确渲染的对象
另外,如果我已经将包含添加到@rings 对象,为什么我还要在“to_json”方法中添加关联?