当我尝试通过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
是的,我再次重新启动我的服务器,以确保和同样的错误发生 –