link_to delete url is not working

前端 未结 7 1371
一个人的身影
一个人的身影 2020-12-06 00:15

I have the following link_to delete url in my app

<%=link_to \"Delete\",blog_path(@blog.id), :method => :delete, :class => \"delete\", :confirm =>         


        
相关标签:
7条回答
  • 2020-12-06 00:42

    In order for link_to to work with the delete method, Rails needs the unobtrusive scripting adapter for jQuery.

    • Make sure that your Gemfile has

      gem 'jquery-rails'

    • Make sure that app/assets/javascripts/application.js has

      //= require jquery
      //= require jquery_ujs

    • Make sure that your app/views/layouts/application.html.erb has

      <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

      inside the head tag. Remove the 'data-turbolinks-track' => true section if you don't plan to use Turbolinks.

    0 讨论(0)
提交回复
热议问题