2017-10-06 75 views
2

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

回答

2

我认为你必须在has_many :apointments, through: :lisings

一个错字使用has_many :appointments, through: :listings

您的MI尝试s 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

也许这会帮助吗?

+0

是的,我刚才发现并纠正了错误,但仍然给我相同的错误 –

+0

在此处进行完整性检查,修复错别字后是否重新启动服务器? – srt32

+0

是的,我再次重新启动我的服务器,以确保和同样的错误发生 –

相关问题