{"id":11107,"date":"2024-08-12T12:54:50","date_gmt":"2024-08-12T12:54:50","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=11107"},"modified":"2024-08-12T12:54:50","modified_gmt":"2024-08-12T12:54:50","slug":"ruby-on-rails-7-destroy-not-showing-alert","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/ruby-on-rails\/ruby-on-rails-7-destroy-not-showing-alert","title":{"rendered":"Ruby on Rails 7 Destroy Not Showing Alert"},"content":{"rendered":"<p>When the user clicks on delete, alert not show and go to this path course_path, but don&#8217;t delete the course.<\/p>\n<h3>Controller<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\">\r\ndef destroy \r\nauthorize @course\r\n@course.destroy \r\nrespond_to do |format| \r\nformat.html { redirect_to courses_url, notice: \"Course was successfully destroyed.\" } \r\nformat.json { head :no_content }\r\nend\r\nend\r\n<\/pre>\n<h3>The view:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"r\">\r\n= link_to 'Destroy', course, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger\r\n<\/pre>\n<h3>Solution:<\/h3>\n<p>&#8211; Rails 7 default use Turbo by default, which changes how form submissions and link interactions work.<br \/>\nSo need to change in view<\/p>\n<p><strong>= link_to &#8216;Destroy&#8217;, course, data: {turbo_method: :delete, turbo_confirm: &#8216;Are you sure?&#8217; }, class: &#8216;btn btn-sm btn-danger&#8217;<\/strong><\/p>\n<h3>NOW What is Turbo?<\/h3>\n<p>Turbo is a set of complementary techniques for speeding up web applications without writing complex JavaScript. It&#8217;s part of the Hotwire suite, which aims to provide a modern, HTML-over-the-wire approach to building web applications.<\/p>\n<h3>Benefits of Turbo<\/h3>\n<ul>\n<li><strong>Improved Performance:<\/strong> Faster page loads and transitions.<\/li>\n<li><strong>Simplified Development:<\/strong> Reduces the need for complex JavaScript.<\/li>\n<li><strong>Enhanced User Experience:<\/strong> Provides app-like feel to web applications.<\/li>\n<li><strong>Reduced Server Load:<\/strong> Partial updates mean less data transfer.<\/li>\n<li><strong>Progressive Enhancement:<\/strong> Works with or without JavaScript enabled.<\/li>\n<li><strong>Seamless Integration:<\/strong> Works well with existing Rails patterns and helpers.<\/li>\n<\/ul>\n<h3>Why Rails 7 Uses Turbo by Default<\/h3>\n<ul>\n<li><strong>Alignment with Rails Philosophy:<\/strong> Emphasizes convention over configuration.<\/li>\n<li><strong>Modern Web Standards:<\/strong> Leverages latest browser capabilities.<\/li>\n<li><strong>Reduced Complexity:<\/strong> Simplifies building reactive applications.<\/li>\n<li><strong>Performance Focus:<\/strong> Aligns with Rails&#8217; goal of developer happiness and application performance.<\/li>\n<li><strong>Ecosystem Consistency:<\/strong> Provides a standard approach for the Rails community.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When the user clicks on delete, alert not show and go to this path course_path, but don&#8217;t delete the course. Controller def destroy authorize @course @course.destroy respond_to do |format| format.html { redirect_to courses_url, notice: &#8220;Course was successfully destroyed.&#8221; } format.json { head :no_content } end end The view: = link_to &#8216;Destroy&#8217;, course, method: :delete, data: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":11108,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-11107","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11107"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=11107"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11107\/revisions"}],"predecessor-version":[{"id":11110,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/11107\/revisions\/11110"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/11108"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=11107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=11107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=11107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}