2017-10-06 70 views
2

當我嘗試通過ActiveAdmin的儀表板查看兩個特定的模型時,我收到以下錯誤。我讀過的所有內容都指向了一個可能的關聯問題,但我不知道如何糾正它。我看到很多人遇到同樣的問題,但還沒有找到任何解決方案。任何幫助將非常感激。Rails 5.1 ActiveAdmin錯誤未定義的方法`klass'爲零:NilClass

NoMethodError in Admin::Listings#index 
undefined method `klass' for nil:NilClass 

NoMethodError in Admin::Buildings#index 
undefined method `klass' for nil:NilClass 

模型

class Company < ApplicationRecord 
    has_many :appointments, through: :listings, dependent: :destroy 
    has_many :listings, through: :users, dependent: :destroy 
    has_many :buildings, through: :users, dependent: :destroy 
    has_many :users, dependent: :destroy 
end 

class User < ApplicationRecord 
    belongs_to :company 
    has_many :apointments, through: :listings 
    has_many :listings, through: :buildings 
    has_many :buildings 
end 

class Listing < ApplicationRecord 
    has_many :companies, through: :users 
    has_many :users, through: :buildings 
    belongs_to :building 
    has_many :appointments 
end 

class Building < ApplicationRecord 
    has_many :companies, through: :users 
    belongs_to :user 
    has_many :appointments, through: :listings 
    has_many :listings, dependent: :destroy 
end 


class Appointment < ApplicationRecord 
    belongs_to :listing 
    has_many :companies, through: :listings 
end 

回答

2

我認爲你必須在has_many :apointments, through: :lisings

一個錯字使用has_many :appointments, through: :listings

您的MI嘗試s p和一個缺失的t

沒有分辨率,但https://github.com/activeadmin/activeadmin/issues/4470看起來也是你的問題。

另外一個想法:

在具有belong_to和您使用的協通過的機型,請嘗試更改奇異。例如:

class Appointment < ApplicationRecord belongs_to :listing has_many :companies, through: :listing # nb: singular here end

也許這會幫助嗎?

+0

是的,我剛纔發現並糾正了錯誤,但仍然給我相同的錯誤 –

+0

在此處進行完整性檢查,修復錯別字後是否重新啓動服務器? – srt32

+0

是的,我再次重新啓動我的服務器,以確保和同樣的錯誤發生 –

相關問題