는 답변을
comments
테이블 열 '과 같이 될 수있다 경로에 관한 부분과 자원 찾기.
일반적인 레일 컨트롤러는 부모로부터 하위 리소스를 찾습니다.
GET /articles/{parent_id}/comments/{id}
GET /articles/0/comments/1
article = articles.find(parent_id = 0)
comment = article.comments.find(id = 1)
다형성 부모와 함께 할 수 없습니다. 자녀에게서 부모를 찾아야합니다.
GET /article/{parent_id}/comments/{id}
GET /questions/{parent_id}/comments/{id}
GET /article/0/comments/1
GET /questions/0/comments/1
parent = comments.select(parent_id = 0).parent
comment = parent.comments.find(id = 1)
라우트를 컨트롤러에 전달할 수 있습니다.
GET /{parent_type}/{parent_id}/comments/{id}
GET /article/0/comments/1
GET /questions/0/comments/1
parent = parent_type.find(parent_id = 0)
comment = parent.comments.find(id = 1)
(나는이 방법을 시도하지 않은 한,이 분명히 의사입니다.)
편집 ...
난 당신이 또한 단지 부모의 각 유형에 대해 하나 개의 매개 변수를 추가 할 수도있을 것 같군요.
GET /article/{article_id}/comments/{id}
GET /questions/{question_id}/comments/{id}
GET /article/0/comments/1
GET /questions/0/comments/1
if article_id
article = articles.find(article_id = 0)
comment = article.comments.find(id = 1)
if question_id
question = questions.find(question_id = 0)
comment = question.comments.find(id = 1)
+100 중첩 된 자원에 대해 "회사 파악"이있는 경우 – Zabba