0
我在我的應用程序中有各種相關的模型。我已經設置了Draper來在父類的初始化時裝飾關聯。Rails德雷珀寶石引發未定義的方法嵌套模型
我有以下類別:
Customer (has_many :accounts)
Account (belongs_to :customer && has_many :facilities && has_one :contact)
Contact (belongs_to :account)
Facility (belongs_to :account)
我發起一個裝飾如下:
@customer = Customer.find_by(:token => params[:token]).decorate
在我account_decorator添加以下內容:
decorates_association :contact
decorates_association :facilities
...和在我的客戶裝飾中,我有:
decorates_association :accounts
我遇到的問題是未定義的方法異常顯示在facility_decorator中定義的任何方法。 contact_decorator工作得很好。我確信我的AR映射是正確的,所以它不可能是這樣。
有什麼建議嗎?
也許有一個與'Facility'裝飾者無關的問題。你有沒有嘗試刪除關聯,只是實例化裝飾'Facility',只是爲了消除這種情況? – Ninjarabbi 2015-02-08 21:42:59
@Ninjarabbi,我已經測試了它自己的實例化設施,並在其上使用了.decorate。這似乎在這種情況下工作,因爲我可以通過它的外觀訪問FacilityDecorator方法 – Herm 2015-02-09 14:53:47
「contact」和「facility」之間沒有區別。沒有看到所有的代碼就很難弄明白。我試圖通過將'account'和'contact'之間的關係改變爲'has_many'來消除因素,看看它是否仍然有效。然後,我會嘗試在這兩個模型之間複製部分代碼,直到找到使'contact'工作和'facility'不工作的原因。 – Ninjarabbi 2015-02-09 21:41:41