我在使用 Ruby 1.8.7 和 Rails 时遇到堆栈级别太深的错误 3.0.4 并使用 Rails 控制台执行了以下命令。
leo%>rails console
Loading development environment (Rails 3.0.4)
ruby-1.8.7-head > leo = Organization.find(1)
SystemStackError: stack level too deep
from /app/models/organization.rb:105:in `parents'
这是有问题的对象..
class Organization < ActiveRecord::Base
has_many :group_organizations, :dependent =>
:delete_all
has_many :groups, :through => :group_organizations
has_many :orders
has_many :product_contracts
has_many :people
accepts_nested_attributes_for :people
has_many :addresses
accepts_nested_attributes_for :addresses
has_many :organizations
has_many :departments
has_many :organization_credits
has_many :documents
validates_presence_of :name
def self.parents
@organizations = Organization.where("is_company = ?",true)
#@organization_parents = []
select_choice = I18n.t("select") + " "+ I18n.t("segments.description")
@organization_parents = [select_choice]
for organization in @organizations
@organization_parents << [organization.name, organization.id]
end
return @organization_parents
end
最佳答案
当您不小心递归地更改属性时,通常会发生此错误。如果您在用户模型中有一个用户名属性,以及一个名为用户名的虚拟属性,即直接更改用户名,您最终会调用虚拟,虚拟再次调用虚拟等等。因此,看看是否有什么东西就像在您的代码中某处发生的那样。
关于ruby-on-rails - Ruby on Rails 中的堆栈级别太深错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5446055/