내 루트 파일은 다음과 같습니다중첩 된 자원 3
resources :countries do
resources :regions do
resources :appartments
end
end
모델 :
Country: has_many :regions
Region: belongs_to :country, has_many :appartments
Appartment: belongs_to: region
Region_controller :
def index
@country = Country.find(params[:country_id])
@regions = @country.regions
end
def show
@country = Country.find(params[:country_id])
@region = @country.regions.find(params[:id])
end
질문 :
난에 아파트를 보여주고 싶은 지역 페이지. 내 지역 컨트롤러의 모범 사례는 무엇입니까?
내가 편집하기 전에 아무 것도 느끼지 않아도된다. 보고있는 지역에 속한 아파트를 보여주고 싶습니까? –