This is listed on the official websi" /> This is listed on the official websi" /> This is listed on the official websi"/>

Ruby on Rails guide DELETE section not working

1.4k views Asked by At
<%= link_to "Destroy", article_path(@article), data: {
                turbo_method: :delete,
                turbo_confirm: "Are you sure?"
              } %>

This is listed on the official website of Ruby on Rails as a simple way of deleting an Active Record. I have the same controller method as they do. This does not delete, nor does it confirm. I have found other methods that successfully delete, but none that confirm. I would like to understand why this doesn't delete, and how I can confirm.

3

There are 3 answers

1
Athira Kadampatta On

This SO post addresses a similar problem and answered by @json fb. Quoting statements from the SO post

This happens if you had locally installed gem versions 7.1.0 or 7.1.1 for turbo-rails

These gem numbers were pushed by accident to Rubygems in October, then yanked. However, since bundler will default to the highest number of your Rails gem when it sets up your new rails app, it will pick turbo-rails version 7.1.0 or 7.1.1 , which will display this flaw

The gems were yanked, so this only affects you if you were developing rails apps between October 2021 and the yank date. TO FIX YOUR COMPUTER: gem uninstall turbo-rails

2
Sulaksh Gupta On
<ul>
<li><%= link_to "Edit", edit_article_url(@article) %> </li>
<li><%= button_to "Destroy", article_path(@article), method: :delete,
            data: { method_turbo_confirm: "Are you sure?" }
 %></li>

Changing link_to to button_to and adding method: :delete worked for me. Although the "Are you sure?" pop up is still not working.

0
Bidan On

try to add status to redirect like here "redirect_to root_path, status: :see_other" For more clarification https://guides.rubyonrails.org/getting_started.html#deleting-an-article

def destroy
    @article = Article.find(params[:id])
    @article.destroy

    redirect_to root_path, status: :see_other
  end