When the user clicks on delete, alert not show and go to this path course_path, but don’t delete the course.

Controller

def destroy 
authorize @course
@course.destroy 
respond_to do |format| 
format.html { redirect_to courses_url, notice: "Course was successfully destroyed." } 
format.json { head :no_content }
end
end

The view:

= link_to 'Destroy', course, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger

Solution:

– Rails 7 default use Turbo by default, which changes how form submissions and link interactions work.
So need to change in view

= link_to ‘Destroy’, course, data: {turbo_method: :delete, turbo_confirm: ‘Are you sure?’ }, class: ‘btn btn-sm btn-danger’

NOW What is Turbo?

Turbo is a set of complementary techniques for speeding up web applications without writing complex JavaScript. It’s part of the Hotwire suite, which aims to provide a modern, HTML-over-the-wire approach to building web applications.

Benefits of Turbo

  • Improved Performance: Faster page loads and transitions.
  • Simplified Development: Reduces the need for complex JavaScript.
  • Enhanced User Experience: Provides app-like feel to web applications.
  • Reduced Server Load: Partial updates mean less data transfer.
  • Progressive Enhancement: Works with or without JavaScript enabled.
  • Seamless Integration: Works well with existing Rails patterns and helpers.

Why Rails 7 Uses Turbo by Default

  • Alignment with Rails Philosophy: Emphasizes convention over configuration.
  • Modern Web Standards: Leverages latest browser capabilities.
  • Reduced Complexity: Simplifies building reactive applications.
  • Performance Focus: Aligns with Rails’ goal of developer happiness and application performance.
  • Ecosystem Consistency: Provides a standard approach for the Rails community.

Support On Demand!

Ruby on Rails