2012-02-26 7 views
2

나는 한 다음 모델 내가 관리자 대시 보드에 BusinessOwner 모델을 추가하려고했습니다 레일 활성

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 

많은 관계로 많은 관리자 : 응용 프로그램에서 파일을 만듭니다

rails generate active_admin:resource BusinessOwner 

라고 business_owners/admin/ 사업자를 보려고하면 다음 오류가 발생합니다.

uninitialized constant BusinessOwner::Owners 
Extracted source (around line #1): 

1: render renderer_for(:index) 

많은 관계가 많은 활성 관리자를 사용하는 방법을 누군가에게 알려 줄 수 있습니까?

답변

2

관계가 옳지 않습니다. belongs_to 관계에

는 레일은

class BusinessOwner < ActiveRecord::Base 
    belongs_to :owner 
    belongs_to :business 
end 

마찬가지로 단수 양식을 사용하기 위해, 올바르게 그건

:through

has_many :businesses, :through => :business_owners 

(즉, 복수의 소유자)를 참조 할 필요가 기대 보통 Active Directory에 대해 생각하기 전에 레일스 콘솔 (OR WRITING TESTS, hehe)을 테스트해볼 가치가있다. bussiness의 테이블에 올바른

+0

당신의 바위. 내 잘못이야. 네, 한 두 가지 테스트가있었습니다. –

2

은 다음과 같이 연결을 수행

class Business < Active Record::Base 
    has_many :business_owners 
    has_many :oweners, :through => :business_owner 
end 
관련 문제