0
각 사이트가 트러스트에 속하고 트러스트에 많은 사이트가있는 앱이 있습니다.Jbuilder에서 belongs_to/has_many 모델 관계 내에서 데이터 가져 오기
이 같은 제이빌더와 JSON 결과를 짓고 있어요 : 블록의 마지막 줄은 NoMethod의 오류를 반환
json.array! (@sites) do |site|
json.id site.id
json.name site.name
json.city site.city
json.state site.state
json.country site.country
json.start_date site.start_date
json.end_date site.end_date
json.trust site.trust, :id, :name # throws error here
end
"무기 호에 대한 정의되지 않은 메서드 'ID'. NilClass를"
그러나 사이트 모델은 belongs_to : trust이고 신뢰 모델은 has_many : sites입니다.
레일스 콘솔을 실행할 때 예상대로 site.trust.id 및 site.trust.name에 액세스 할 수 있습니다.
어떤 아이디어가 잘못 되었나요?