gpt4 book ai didi

ruby-on-rails - 单表继承事件管理模型映射问题 rails 4

转载 作者:行者123 更新时间:2023-12-03 15:52:10 25 4
gpt4 key购买 nike

我创建了一个具有单表继承的多用户这里是我的模型

# user.rb 

class User < ActiveRecord::Base
end

这是用户模型,所有其他模型都是从数据库中的用户继承而来的,它们是一种既存储用户类型又保存用户类型的模型
# customer.rb

class Customer < User
end

# space_owner.rb

class SpaceOwner < User
end

**当我在 active_admin 中映射这些时rails 4 显示了一个错误**
Showing /home/rabnawaz/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-0a5a15b88bff/app/views/active_admin/resource/index.html.arb where line #2 raised:

undefined method `chain' for nil:NilClass
Extracted source (around line #709):
def chain
@chain ||= begin
a = source_reflection.chain
b = through_reflection.chain
chain = a + b
chain[0] = self # Use self so we don't lose the information from :source_type

这是我创建时遇到的错误 active_admin显示用户的文件

你能给我一个解决方案吗?

这是我用来创建多个用户的设计路线
devise_for :admin_users, ActiveAdmin::Devise.config
ActiveAdmin.routes(self)

devise_for :customers, :controllers => {
:registrations=>"customers/registrations",
:passwords=>"customers/passwords"
},:skip => :sessions
devise_for :space_owners, :controllers => {
:registrations=>"space_owners/registrations",
:passwords=>"space_owners/passwords"
},:skip => :sessions

最佳答案

给出这个答案引用自 https://github.com/activeadmin/activeadmin/issues/3957 :

After some research I figured out that this error appears when active_record can't automatically infer the name for a nestedassociation. Workaround to handle this could for instance be usingthrough on nested associations.


从您的问题中也不清楚您是否确实向 ActiveAdmin 注册了 User 子类。

关于ruby-on-rails - 单表继承事件管理模型映射问题 rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39193259/

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