我有以下型号
class Owner < ActiveRecord::Base
has_many :business_owners
has_many :businesses, :through => :business_owner
end
class Business < Active Record::Base
has_many :business_owners
has_many :businesses, :through => :business_owner
end
class BusinessOwner < ActiveRecord::Base
belongs_to :owners
belongs_to :businesses
end
我尝试将BusinessOwner模型添加到管理信息中心:
rails generate active_admin:resource BusinessOwner
在app / admin /中创建一个名为business_owners的文件 当我尝试查看业主时,我收到以下错误:
uninitialized constant BusinessOwner::Owners
Extracted source (around line #1):
1: render renderer_for(:index)
有人可以告诉我如何使用多个关系的主动管理员吗?
答案 0 :(得分:2)
你的人际关系看起来不对。
在belongs_to
关系上,Rails希望您使用单数形式
class BusinessOwner < ActiveRecord::Base
belongs_to :owner
belongs_to :business
end
同样,您需要正确引用:through
has_many :businesses, :through => :business_owners
(即复数所有者)
在考虑ActiveAdmin之前,通常需要启动Rails控制台(或写作测试,呵呵)来测试这些东西;)
答案 1 :(得分:2)
在商务表中纠正做这样的关联:
class Business < Active Record::Base
has_many :business_owners
has_many :oweners, :through => :business_owner
end