1
我一直在這一個抨擊我的頭靠在牆上,我無法讓它工作。我有三個型號:Rails 3,Rspec /黃瓜和工廠女孩:嵌套/關聯對象沒有方法錯誤
class Instrument < ActiveRecord::Base
has_many :analytical_methods
has_many :analytes, :through => :analytical_methods
accepts_nested_attributes_for :analytical_methods
attr_accessible :name, :analytical_methods_attributes
end
class AnalyticalMethod < ActiveRecord::Base
belongs_to :instrument
has_many :analytes
accepts_nested_attributes_for :analytes
attr_accessible :name, :analytes_attributes
end
class Analyte < ActiveRecord::Base
belongs_to :analytical_method
attr_accessible :name
end
而且我有以下工廠:
Factory.define :analyte do |analyte|
analyte.name "Test analyte"
end
Factory.define :analytical_method do |analytical_method|
analytical_method.name "Test method"
analytical_method.association :analyte
end
Factory.define :instrument do |instrument|
instrument.name "Test instrument"
instrument.association :analytical_method
instrument.association :analyte
end
任何時候,我嘗試廠(:儀器)或廠(:analytical_method),它引發以下錯誤:
NoMethodError:
undefined method `analyte=' for #<AnalyticalMethod:0x00000104c44758>
我錯過了一些荒謬的錯字或什麼?該網站工作得很好,但測試保持失敗。感謝任何幫助恢復我的理智!