1

Article多くのがあるとしましょうComments

Comments別の「記事 XYZ のコメントを作成」ページで記事に追加されます。

すべての記事ページに「コメントを追加」リンクを追加したいと思います。

しかし、コメント コントローラーでは、コメントが追加された親記事に関する情報が必要です。

article_idでは、記事情報 ( ) をlink_toからコメント作成ページに渡すにはどうすればよいでしょうか?

4

1 に答える 1

1
<%= 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...

于 2010-11-02T16:44:49.503 に答える