중첩 된 리소스에서 ID에 액세스하려면 어떻게해야합니까? @[email protected]
에 ID가 people_id가 아닙니다 .i 오류가 Couldn't find People without an ID
이됩니다. 미리 감사드립니다.중첩 된 리소스에서 ID를 가져 오는 방법은 무엇입니까?
모델
class City < ActiveRecord::Base
has_many :peoples
end
class People < ActiveRecord::Base
belongs_to :city
end
컨트롤러
def show
@city = City.find(session[:city_id])
@[email protected]
@[email protected](params[:id])
end
경로
resources :city, :people
resources :cities do
resources :peoples
end
미안하지만 오타가 카피 붙여 넣기였습니다. 그래요.하지만 문제는 사람 ID가없는 사람을 찾을 수 없다는 것입니다. 이는 사람 인스턴스에 ID가 없으므로 경로와 관련이 있다고 생각하게합니다. – katie