2012-07-25 91 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版本不兼容。