link_to delete url is not working

前端 未结 7 1370
一个人的身影
一个人的身影 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:25

    Make sure these lines appear in application.js :

     //= require jquery
     //= require jquery_ujs
    
    0 讨论(0)
  • 2020-12-06 00:25

    You can try with 'data-method' instead of :method.

    <%=link_to "Delete",blog_path(@blog.id), 'data-method' => :delete, :class => "delete", :confirm => "Are you sure ?"%> 
    

    You can check on jquery_ujs.js the following piece of code:

    // Handles "data-method" on links such as:
    // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
    
    0 讨论(0)
  • 2020-12-06 00:30

    Are you using jQuery? If so, I think the problem could be that you are using jQuery without the updated rails.js file.

    Download rails.js here: https://github.com/rails/jquery-ujs/raw/master/src/rails.js Drop it in your javascripts directory, overwriting the rails.js that comes default with rails.

    Add a javascript include line to include it.

      <%= javascript_include_tag "rails" %>
    

    Put this after your Jquery include tag. You probably also want to disinclude the javascript defaults if you don't plan on using prototype.

    I included jQuery UI in my application, I found that delete is now working as show, but after doing above Resolved Issue.

    0 讨论(0)
  • 2020-12-06 00:36

    Ensure that you have java script turned on. Otherwise :method => :delete acts just as show in Rails.

    0 讨论(0)
  • 2020-12-06 00:36

    you should use

    <%=button_to "Delete",blog_path(@blog.id), :method => :delete, :class => "delete", :confirm => "Are you sure ?"%>  
    
    0 讨论(0)
  • 2020-12-06 00:37

    If you're using restful routing for blogs, then the following should work:

    <%= link_to "Delete", @blog, :method => :delete, :confirm => "Are you sure ?"%>
    
    0 讨论(0)
提交回复
热议问题