简体   繁体   English

Rails:堆栈级别太深的错误

[英]Rails: Stack level too deep error

My rails app has 3 models. 我的rails应用程序有3个型号。 Trail, Region and Feature. 小道,地区和特色。 I am able to interact with these models fine in my lib/tasks directory. 我可以在lib / tasks目录中很好地与这些模型进行交互。 I used anemone to crawl and populate the database. 我用anemone来抓取并填充数据库。 Examples of calls I made on the models: 我在模型上调用的示例:

Trail.find_or_initialize_by_title(detail_title)

I am now trying to write a controller that uses the model. 我现在正在尝试编写一个使用该模型的控制器。

class TrailController < ApplicationController
    def index
        render :json => Trail.all
    end
end

Now if i open rails console and try app.get('trail/index') I get a 500 return code and I see the following in my development.log 现在,如果我打开rails控制台并尝试app.get('trail/index')我得到一个500返回代码,我在我的development.log看到以下内容

SystemStackError (stack level too deep): SystemStackError(堆栈级别太深):
app/controllers/trail_controller.rb:23:in `index' app / controllers / trail_controller.rb:23:在'index'中

So I'm obviously causing some infinite recursion. 所以我显然会引起一些无限的递归。 Line 23 corresponds to the body of the index method. 第23行对应于索引方法的主体。 I've tried the other models in my app: Feature and Region and the result is the same. 我在我的应用程序中尝试过其他模型:功能和区域,结果是一样的。 Can someone tell me what I'm doing wrong here, or how I can get more tracing to figure out what exactly is recursing infinitely? 有人可以告诉我这里我做错了什么,或者我怎么能得到更多的追踪来弄清楚究竟什么是无限递归?

My models are very simple: 我的模型非常简单:

class Feature < ActiveRecord::Base 
  attr_accessible :name 
  has_and_belongs_to_many :trails 
  validates :name, :presence => true
end 

class Region < ActiveRecord::Base 
  attr_accessible :hash_key, :name 
  has_many :trails 
  validates :hash_key, :name, :presence => true 
end 

class Trail < ActiveRecord::Base 
  # attr_accessible :title, :body 
  has_and_belongs_to_many :features 
  validates :title, :presence => true    
end

It appears this is somehow being caused by the searchlogic gem. 看来这是由searchlogic gem引起的。 I have this in my Gemfile: 我在我的Gemfile中有这个:

gem 'rd_searchlogic', :require => 'searchlogic', :git => 'git://github.com/railsdog/searchlogic.|~                                                                                                    

When i comment out that line, run bundle install and retry app.get things work fine. 当我注释掉那一行时,运行bundle install并重试app.get工作正常。 So searchlogic is somehow interfering with Trail.all. 所以searchlogic以某种方式干扰了Trail.all。 Why won't Trail.all work with searchlogic installed? 为什么Trail.all不能安装searchlogic?

The rd_searchlogic gem was the source of the issue. rd_searchlogic gem是问题的根源。 http://kiranb.scripts.mit.edu/blog/?p=247 talks about the issue. http://kiranb.scripts.mit.edu/blog/?p=247谈论这个问题。 "Any named scope Searchlogic creates is dynamic and created via method_missing. And because Rails 3.1 changed around activerecord so much, Searchlogic calls a missing method on activerecord, which then gets rerouted to searchlogic." “Searchlogic创建的任何命名范围都是动态的,并通过method_missing创建。由于Rails 3.1在activerecord周围发生了很大变化,因此Searchlogic在activerecord上调用了一个缺失的方法,然后将其重新路由到searchlogic。”

I decided to switch to meta_where, only to learn that it's not supported from Rails 3.1 onwards. 我决定切换到meta_where,只是为了了解它从Rails 3.1开始不受支持。 I'm running Rails 3.2.8. 我正在运行Rails 3.2.8。 Squeel is the replacement, and works great on Rails 3.2.8: https://github.com/ernie/squeel Squeel是替代品,在Rails 3.2.8上运行良好: https//github.com/ernie/squeel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM