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
谢谢!
最好。
您是否知道'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
你已经定义了2'has_many:credit';我认为第二个'应该是'项目' – Baldrick 2012-07-25 15:28:53