我从 rails "ActiveSupport::JSON::Encoding::CircularReferenceError" 得到一个错误,
当它说我有一个引用自身的对象时,我不确定该错误是什么意思。有人可以解释一下,并帮助我了解如何解决吗?
错误来自以下代码。在我的模型中,调用
范围 :search_wineries, lambda{|wineries|{:joins => :winery, :conditions =>["wineries.id IN (?)", wineries]}} 范围 :search_varietals, lambda{|varietals|{:joins => :varietals, :conditions => ["varietals.id IN (?)",varietals] }} 范围 :search_wines, lambda{|wines|{:conditions=>["wines.id IN (?)",wines]}} def self.search_wines(参数) 范围=自我 [:wineries,:varietals,:wines].each do |s| scope = scope.send("search_#{s}", params[s]) if !params[s].empty? 结尾 范围 结尾
这是从我的控制器调用的
return_wines = Wine.search_wines({葡萄酒:葡萄酒,品种:品种,葡萄酒:葡萄酒}) 渲染 :json => return_wines.to_json(:include=>[:winery,:varietals])