title: How do I make rails recognize a correct id of an active record?
body: <p>I am making a board which consists of "post" model and "comment" model.</p>
  
  <p>The board I'm making doesn't need signing-in procedure, so the password is needed for a deletion of a post or a comment.</p>
  
  <p>When I am trying to delete a post, the code below works well.
  (If a user click the "Delete" button, the hidden DIV which has a password form appears, so I used form_for.)</p>
  
  <pre><code>&lt;%= link_to_function "Delete", "$('#post_password_box').toggle()" %&gt; |
  &lt;div id="post_password_box"&gt;
    &lt;%= form_for(@post, url: { action: "destroy"}, html: { method: :delete, class: nil, id: nil}) do |f| %&gt;
      &lt;%= f.label :password %&gt;
      &lt;%= f.password_field :password %&gt;&lt;br&gt;
  
      &lt;%= f.submit "Commit", class: "btn", data: { confirm: "Are you sure?" } %&gt;
      &lt;%= button_to_function "Cancel", "$('#post_password_box').hide()", class: "btn" %&gt;
    &lt;% end %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So, I used the similar code when it comes to delete the comment.</p>
  
  <pre><code>  &lt;% @comments.each do |comment| %&gt;
      &lt;li class="author"&gt;&lt;%= comment.author %&gt;&lt;/li&gt;
      &lt;li class="content"&gt;&lt;%= comment.content %&gt;&lt;/li&gt;
      &lt;li class="date"&gt;&lt;%= comment.created_at.localtime.strftime("%r") %&gt;&lt;/li&gt;
      &lt;li class="button"&gt;
        &lt;%= link_to_function "X", "$(this).next().toggle()" %&gt;
        &lt;div class="comment_password_box"&gt;
          &lt;%= form_for(comment, url: {controller: "comments", action: "destroy"}, html: {method: :delete, class: nil, id: nil}) do |f| %&gt;
            &lt;%= f.label :password %&gt;
            &lt;%= f.password_field :password %&gt;
  
            &lt;%= f.submit %&gt;
          &lt;% end %&gt;
        &lt;/div&gt;
      &lt;/li&gt;
    &lt;% end %&gt;
  </code></pre>
  
  <p>At a glance, The code above seems to work well, but there is a problem that the code doesn't delete a proper comment.</p>
  
  <p>For example, if the id of a post is 20 and the id of a comment I want to delete is 10, it deletes the comment whose id is 20.</p>
  
  <p>And I found the problem comes from the fact that the form tag's action attributes is like below in every comment.</p>
  
  <pre><code>        &lt;form accept-charset="UTF-8" action="/comments/20" method="post"&gt;&lt;div style="margin:0;padding:0;display:inline"&gt;&lt;input name="utf8" type="hidden" value="&amp;#x2713;" /&gt;&lt;input name="_method" type="hidden" value="delete" /&gt;&lt;input name="authenticity_token" type="hidden" value="Y2oBuoIxa+9yPLC5WflKVVELw3jgKsi9s9/8Cfvr2u8=" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>What should I do to make rails find the proper form tag's action attribute's value? (In this case, it should be "/comments/10", instead of "/comments/20".)</p>