Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8453117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:41:08+00:00 2026-06-10T11:41:08+00:00

I am making a board which consists of post model and comment model. The

  • 0

I am making a board which consists of “post” model and “comment” model.

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.

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.)

<%= link_to_function "Delete", "$('#post_password_box').toggle()" %> |
<div id="post_password_box">
  <%= form_for(@post, url: { action: "destroy"}, html: { method: :delete, class: nil, id: nil}) do |f| %>
    <%= f.label :password %>
    <%= f.password_field :password %><br>

    <%= f.submit "Commit", class: "btn", data: { confirm: "Are you sure?" } %>
    <%= button_to_function "Cancel", "$('#post_password_box').hide()", class: "btn" %>
  <% end %>
</div>

So, I used the similar code when it comes to delete the comment.

  <% @comments.each do |comment| %>
    <li class="author"><%= comment.author %></li>
    <li class="content"><%= comment.content %></li>
    <li class="date"><%= comment.created_at.localtime.strftime("%r") %></li>
    <li class="button">
      <%= link_to_function "X", "$(this).next().toggle()" %>
      <div class="comment_password_box">
        <%= form_for(comment, url: {controller: "comments", action: "destroy"}, html: {method: :delete, class: nil, id: nil}) do |f| %>
          <%= f.label :password %>
          <%= f.password_field :password %>

          <%= f.submit %>
        <% end %>
      </div>
    </li>
  <% end %>

At a glance, The code above seems to work well, but there is a problem that the code doesn’t delete a proper comment.

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.

And I found the problem comes from the fact that the form tag’s action attributes is like below in every comment.

        <form accept-charset="UTF-8" action="/comments/20" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="delete" /><input name="authenticity_token" type="hidden" value="Y2oBuoIxa+9yPLC5WflKVVELw3jgKsi9s9/8Cfvr2u8=" /></div>

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”.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:41:10+00:00Added an answer on June 10, 2026 at 11:41 am

    Let rails generate the URL for you. At the moment you’re setting the URL yourself but you’re not specifying a value for :id so rails takes the current value of params[:id]

    Try

    form_for(comment, :method => :delete)
    

    Instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a board game and I need to action a button which
I'm making a message board application. Users can make a post, each post requires
I'm making a Tic-tac-toe game and i have a board class which contains 9
I am making a board game and I need to put the player 1
Making an adobe flex ui in which data that is calculated must use proprietary
I am using cakePHP and is making a very simple message board. I came
I needed some help in trying to optimize this code portion ... Basically here's
Im making a program about the game Go and im trying to write some
I'm making a sort of a tier board style list, so each record can
I'm making a custom app which should show the Name and the FormattedID. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.