ネストされたリソースを使用していますが、リンクを適切な場所に移動させるために渡すオブジェクトがわかりません。コメントは投稿に属し、質問はコメントに属します。投稿のインデックス ページから質問のインデックス ページにリンクしようとしています。
これは、routes.rb ファイルがどのように見えるかです:
resources :posts do
resources :comments do
end
end
resources :comments do
resources :questions do
end
end
投稿インデックス ファイル内のリンク:
<% post.comments.select(:body).order('created_at desc').limit(2).each do |comment| %>
<%= link_to (comment.body), comment_questions_path(comment, @question) %>
<% end %>
これにより、次のエラーが表示されます。
missing required keys: [:comment_id]
'rake routes | grep comment_question':
comment_questions GET /comments/:comment_id/questions(.:format) questions#index
comment_question GET /comments/:comment_id/questions/:id(.:format) questions#show
ありがとう!