2017-11-04 11 views
-3

特定のコメントを表示するだけのビューファイルであるshow.html.erbに行きたいと思います。コメントは記事の下に関連付けられています。あなたのroutesあなたパットで関連オブジェクトのIDを渡してlink_toヘルパーを使用するにはどうすればよいですか?

# commentcontroller 
def show 
    @article =Article.find(params[:id]) 
end 
+2

周囲のコード、問題の複製方法、問題を解決するために何を試みたのかを人々が理解できるよう、いくつかの情報を追加してください。また、適切なマークアップを使用して質問内のコードの書式を設定します。 –

+0

プロジェクトのルートで 'rake routes'を実行して私たちを見せてもらえますか? –

+0

プレフィックス動詞URIパターンコントローラ#アクションarticle_comments GET/articles /:article_id/comments comments#index POST/articles /:article_id/comments comments#create new_article_comment GET/articles /:article_id/comments/new comments#new article_comment GET /記事#:/ article_id/comments /:idコメント#PATCH /articles/:article_id/comments/:id(.:format)コメント#アップデートPUT /articles/:article_id/comments/:id(.:format)comments#update DELETE /articles/:article_id/comments/:id(.:format) –

答えて

0

をベースにidと

/articles/3/comments/2 

2及び3:<%= link_to 'Show Comment ? %>

を使用する方法

これは次のようにルートを有していてもよく、コメントコントローラでshowアクションですコメントでは、それは動作する必要があります:

link_to('Show Comment', controller: 'comments', action: 'show', id: comment.id, article_id: comment.article.id)

関連する問題