gpt4 book ai didi

ruby-on-rails - Rails 5.1 ActiveAdmin 错误未定义方法 `klass' 为 nil :NilClass

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:02 25 4
gpt4 key购买 nike

当我尝试通过 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

最佳答案

我认为您在 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

也许这会有帮助?

关于ruby-on-rails - Rails 5.1 ActiveAdmin 错误未定义方法 `klass' 为 nil :NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46613118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com