Article
多くのがあるとしましょうComments
。
Comments
別の「記事 XYZ のコメントを作成」ページで記事に追加されます。
すべての記事ページに「コメントを追加」リンクを追加したいと思います。
しかし、コメント コントローラーでは、コメントが追加された親記事に関する情報が必要です。
article_id
では、記事情報 ( ) をlink_to
からコメント作成ページに渡すにはどうすればよいでしょうか?
Article
多くのがあるとしましょうComments
。
Comments
別の「記事 XYZ のコメントを作成」ページで記事に追加されます。
すべての記事ページに「コメントを追加」リンクを追加したいと思います。
しかし、コメント コントローラーでは、コメントが追加された親記事に関する情報が必要です。
article_id
では、記事情報 ( ) をlink_to
からコメント作成ページに渡すにはどうすればよいでしょうか?
<%= link_to "add comment", new_comment_path(:article_id => article_id) %>
Then in your Comments controller, the "new" action:
@article_id = params[:article_id]
Then in the Views/Comments/new.html.erb you have access to the @article_id variable and are able to insert into the form with a hidden field and pass it to the create action...