2012-07-25 90 views
8

其实我是一个很多模型的项目。我需要找到一个当前用户所有信用/设备/项目(我认为没有用的表只有两列(id &得分),所以我把这个表合并到连接表中)。轨道:堆栈层太深

我得到这个错误:

SystemStackError in Users#show 

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

stack level too deep 

而且,这两个型号:

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 

谢谢!

最好。

+1

您是否知道'has_and_belongs_to_many'关系?检查http://guides.rubyonrails.org/association_basics.html#the-has_and_belongs_to_many-association。另外,当你说'has_many'时,它必须是'credits'而不是'credit'。 – 2012-07-25 15:28:12

+0

你已经定义了2'has_many:credit';我认为第二个'应该是'项目' – Baldrick 2012-07-25 15:28:53

回答

15

堆栈层次深点,不定式递归调用,我会说你与

has_many :credit, :through => :credit, 

,明确引入某种形式的循环。

0

您需要将Rails版本升级到最新版本才能解决此问题。

另一种选择是将ruby版本降级为旧版本。

您正在收到此问题,因为您使用的rails版本与ruby版本不兼容。