ruby on rails link_to delete method not working

后端 未结 7 1501
挽巷
挽巷 2021-02-14 06:04

I am trying to delete a post using the code below:

<%= link_to \'Destroy\', post, :method => :delete, :onclick => \"return confirm(\'Are you sure you wa         


        
7条回答
  •  渐次进展
    2021-02-14 06:31

    Check the whitespaces.

    I checked all the comments here. All the includes were set correctly. But I noticed that deleting articles did not work, while deleting comments would work. After rewriting some code and checking here and there, I found two files that looked identically in the editor, but one version would work and one would not work!

    curry-blog/app/views/articles/index.html.erb:

    Listing Articles

    <%= link_to 'New article', new_article_path %>                          <% @articles.each do |article| %>                                                <% end %>
    TitleText
    <%= article.title %><%= article.text %><%= link_to 'Show', article_path(article) %><%= link_to 'Edit', edit_article_path(article) %><%= link_to 'Delete', article_path(article), method: :delete, data: { confirm: 'Are you sure?' } %>

    However, looking at the files with xxdiff I found that in one version only tabs where used, while the other also used blanks. Probably, from copy pasting code from the tutorial. Replacing the blanks with tabs did therefore fix the problem.

提交回复
热议问题