레일스 3.1 앱에 문제가 있습니다. 카운티/카운티 및 타운/타운이라는 두 개의 컨트롤러 & 모델이 있습니다.레일 3.1 has_many & belongs_to로 정의되지 않은 메소드
카운티 모델의 모델은 has_many :towns
이고 타운 모델은 belongs_to :county
입니다.
마을 정보 페이지에 카운티 이름을 표시하여 제목을 '마을 정보 -county-name-'(으)로 표시하려고합니다. 그러나 %h1 Towns in #{@towns.county.name}
을 입력하면 undefined method 'county'
오류가 발생합니다.
인덱스의 마을 컨트롤러 카운티 컨트롤러
def index
@towns = Town.all
end
입니다 :
def index
@counties = County.all
end
내 routes.rb
resources :counties, :path => "/locations" do
resources :towns, :path => "/"
end
내가 뭘되고 잘못?
편집 : 내 마을/인덱스 뷰이 사용하고는 town.county.id
및 town.county.name
를 보여줍니다
- @towns.each do |town|
%tr
%td= town.county.id
%td= town.county.name
%td= town.name
%td= town.description
%td= town.slug
카운티. 핀트가 나를 위해 고쳐주었습니다.] –