Почему я получающий “SystemStackError: уровень стека слишком глубоко” в моей модели rails3 beta4

Я получаю следующую ошибку: SystemStackError: stack level too deep при выполнении следующего кода в rails3 beta4 под ruby 1.9.2-rc1:

ruby-1.9.2-rc1 > f = Forum.all.first
  => #<Forum id: 1, title: "Forum 1", description: "Description 1", content: "Content 1", parent_id: nil, user_id: 1, forum_type: "forum", created_at: "2010-07-17 04:39:41", updated_at: "2010-07-17 04:39:41", icon_file_name: nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: nil> 
ruby-1.9.2-rc1 > f.children
  => [#<Forum id: 2, title: "Thread 2", description: "Description 2", content: "Content 2", parent_id: 1, user_id: 1, forum_type: "thread", created_at: "2010-07-17 04:40:17", updated_at: "2010-07-17 04:40:17", icon_file_name: nil, icon_content_type: nil, icon_file_size: nil, icon_updated_at: nil>] 
ruby-1.9.2-rc1 > f.forum_type = "thread"
  => "thread" 
ruby-1.9.2-rc1 > f.save
SystemStackError: stack level too deep
from /Users/emilkampp/.rvm/rubies/ruby-1.9.2-rc1/lib/ruby/1.9.1/irb/workspace.rb:80
Maybe IRB bug!!
ruby-1.9.2-rc1 > 

И это вызывается следующим кодом:

# Before and after filters
# 
before_update :update_all_nested_objects, :if => :forum_type_changed?

protected
  # Checks if the +forum_type+ has been changed
  # 
  def forum_type_changed?
    self.forum_type_changed?
  end

  # Updates all nested upjects if the +forum_type+ has been changed
  # 
  # This will trigger the +update_all_nested_objects+ method on all touched children, thus 
  # starting a chain-reaction all the way through the forum-tree.
  # 
  # NOTE: This is where the error is triggered, since this is the only non-tested looping code, and my test-
  #       cases hasn't changed since this was added.
  # 
  def update_all_nested_objects
    children.each do |child|
      child.forum_type = child_type
      child.save
    end
  end

Так, что продолжается. Я проверял вокруг немного, но ни у кого, кажется, нет той же проблемы. Или это не та же рубиновая версия, таким образом workflow.rb файл отличается, или stack level to deep вызывается чем-то еще.

Любая справка будет значительно цениться!

С уважением

//Emil

17
задан Ekampp 17 July 2010 в 06:22
поделиться

1 ответ

Вы вызываете тот же метод в самом методе

  def forum_type_changed?
    self.forum_type_changed?  #This will never ending process hence it gives error
  end

Я думаю, у вас такое же имя метода и имя столбца , которое вызывает проблему, измените имя вашего метода затем

  def check_forum_type_changed?
    self.forum_type_changed?  #method name and column name are different
  end
37
ответ дан 30 November 2019 в 11:43
поделиться
Другие вопросы по тегам:

Похожие вопросы: