當我嘗試通過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
是的,我剛纔發現並糾正了錯誤,但仍然給我相同的錯誤 –
在此處進行完整性檢查,修復錯別字後是否重新啓動服務器? – srt32
是的,我再次重新啓動我的服務器,以確保和同樣的錯誤發生 –