School
, Course
및 Section
의 세 모델이 있습니다. 모두가 일대 다 관계에 있습니다 (학교 has_many
코스, 및 코스 has_many
섹션, 해당 belongs_to
관계도 모델에 설정 됨). 또한 다음과 같은 리소스 (제외 나중에 설정해야합니다)이 : 중첩 된 자원의 일부로서 작동 할 수'새로운'방법을 쓸 때
resources :schools do
resources :courses
end
resources :sections #not part of the nest
sections
있지만, 나는 단지 하나의 레이어 깊은 Rails guide 권장 둥지 이후를 유지했다. 이 (SectionsController
에서) 새 섹션을 생성에 관해서, 그것은 항상 "할 수 없습니다 올릴 것 course_id
def new
@course = Course.find(params[:id]) #this line results in an error
@section = @course.sections.new
end
첫 번째 라인을 통해 과정에 연결 한 경우
그래서, 내 문제입니다 id : : course_id, 등등을 사용하는 다양한 조합을 시도해 보았음에도 불구하고 과거에 얻을 수없는 "ID없는 코스 찾기"오류가 발생했습니다. Course
은 중첩 된 리소스이므로 누락 된 것이 있습니까? 당신의 도움을 주셔서 감사합니다!
rake routes
를 실행, 여기에 출력됩니다 :
sections GET /sections(.:format) sections#index
POST /sections(.:format) sections#create
new_section GET /sections/new(.:format) sections#new
edit_section GET /sections/:id/edit(.:format) sections#edit
section GET /sections/:id(.:format) sections#show
PUT /sections/:id(.:format) sections#update
DELETE /sections/:id(.:format) sections#destroy
school_courses GET /schools/:school_id/courses(.:format) courses#index
POST /schools/:school_id/courses(.:format) courses#create
new_school_course GET /schools/:school_id/courses/new(.:format) courses#new
edit_school_course GET /schools/:school_id/courses/:id/edit(.:format) courses#edit
school_course GET /schools/:school_id/courses/:id(.:format) courses#show
PUT /schools/:school_id/courses/:id(.:format) courses#update
DELETE /schools/:school_id/courses/:id(.:format) courses#destroy
schools GET /schools(.:format) schools#index
POST /schools(.:format) schools#create
new_school GET /schools/new(.:format) schools#new
edit_school GET /schools/:id/edit(.:format) schools#edit
school GET /schools/:id(.:format) schools#show
PUT /schools/:id(.:format) schools#update
DELETE /schools/:id(.:format) schools#destroy
root /
'rake routes'를 실행하고 결과를 질문에 추가하십시오. – weltschmerz
출력 추가 - 감사합니다. – daspianist