Ruby on rails Rails 5.1 ActiveAdmin错误未定义方法“klass';零级:零级
当我试图通过ActiveAdmin的仪表板查看两个特定模型时,我收到以下错误。我读到的所有内容都指向一个可能的关联问题,但我不确定如何纠正它。我看到很多人都有同样的问题,但还没有找到解决办法。任何帮助都将不胜感激Ruby on rails Rails 5.1 ActiveAdmin错误未定义方法“klass';零级:零级,ruby-on-rails,ruby,activeadmin,Ruby On Rails,Ruby,Activeadmin,当我试图通过ActiveAdmin的仪表板查看两个特定模型时,我收到以下错误。我读到的所有内容都指向一个可能的关联问题,但我不确定如何纠正它。我看到很多人都有同样的问题,但还没有找到解决办法。任何帮助都将不胜感激 NoMethodError in Admin::Listings#index undefined method `klass' for nil:NilClass 或 模型 class Company < ApplicationRecord has_many :appoint
NoMethodError in Admin::Listings#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
class公司
我想你在的has\u many中有一个输入错误:apointments,through::lisings
尝试使用has\u many:appointment,through::listings
你缺少了一个p和一个t
没有解决方案,但看起来你的问题也一样
还有一个想法:
在具有属于
且您使用该关联表示“通过”的模型上,尝试将其更改为“单数”。例如:
班级预约<申请记录
属于:列表
有很多:公司,通过::上市#注意:这里是单数
终止
也许这会有帮助?是的,我早些时候发现并纠正了这个问题,但仍然在这里给我相同的错误检查,您是否在纠正错误后重新启动了服务器?是的,我再次重新启动了服务器以确保出现相同的错误。我认识的一些人还建议我将一些关联单列,但这也不起作用:(如果在
rails c
中启动应用程序,是否可以浏览所有关联?
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