Ruby-on-rails rails:堆栈级别太深

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11653117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 03:45:08  来源:igfitidea点击:

rails : stack level too deep

ruby-on-railsrubysqlite

提问by msusplugas

Actually i'm on a project for a model many->many. I need to find with a current user all credits/devices/project (and I think it's useless to have a table credit with only two column (id & score) so I merge this table to the join table).

实际上,我正在做一个模型很多-> 很多的项目。我需要找到当前用户的所有积分/设备/项目(我认为只有两列(id 和 score)的表积分是没用的,所以我将此表合并到连接表中)。

I get this error :

我收到此错误:

SystemStackError in Users#show

Showing app/views/shared/_credit.html.erb where line # raised:

stack level too deep

And the two model :

和两个模型:

class **Credit** < ActiveRecord::Base
  attr_accessible :created_at, :credit_id, :device_id, :project_id, :score, :user_id

belongs_to :device
belongs_to :user
belongs_to :project
belongs_to :score

end

class **User** < ActiveRecord::Base

has_many :credit
has_many :credit, :through => :credit, foreign_key: "user_id", dependent: :destroy
end

Thank !

谢谢 !

Best.

最好的事物。

回答by bento

Stack level to deep points to an infinitive recursive call, and I would say you get that with

堆栈级别到深度指向一个不定式递归调用,我会说你明白了

has_many :credit, :through => :credit,

which clearly introduces a cycle of some sort.

这清楚地引入了某种循环。