当我尝试通过ActiveAdmin的信息中心查看两个特定模型时,我收到以下错误。我读过的所有内容都指向可能的关联问题,但我不确定如何纠正它。我看到很多人都遇到了同样的问题,但没有找到任何解决方案。任何帮助将非常感激。
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
答案 0 :(得分:3)
我认为你在has_many :apointments, through: :lisings
尝试使用has_many :appointments, through: :listings
你缺少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
也许那会有帮助吗?