4

I am using gem 'twitter-bootstrap-rails' for rails bootstrap

I have a few links on a page Rails code

<td><%= link_to 'Destroy', swimming_classschedule, method: :delete, data: { confirm: 'Are you sure?' } %></td>

 <li> <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link'  %> </li>

html code:

     <a href="/users/sign_out" class="navbar-link" data-method="delete" rel="nofollow">Logout</a>

<td><a href="/swimming/students/1" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a></td>

      <td><a href="/swimming/students/3" data-confirm="Are you sure?" data-method="delete" rel="nofollow">Destroy</a></td>

Whenever I click to delete a student I got logged out. I am totally confused

wwli
  • 2,623
  • 6
  • 30
  • 45
  • 1
    And if you remove logout link, what happens then? You use Devise? Isn't the log saying `WARNING: Can't verify CSRF token authenticity` – Mike Szyndel Jun 23 '13 at 20:45

2 Answers2

12

I had the same problem.. I read in the forums that it was due to javascript issues.

In application.js, I previously removed the original files because I thought they weren't needed as I was using bootstrap.js. I put it back in the file and now the delete method works again!

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .
Bilton Tran
  • 386
  • 5
  • 6
  • 1
    I added only jquery_ujs after jquery, which is the responsible for that – sites Aug 10 '16 at 22:11
  • Hi @juanpastas, Thank you for your commennt! I have added the `jquery_ujs` after jquery, then it works perfectly. – AdminDev826 Nov 22 '18 at 04:03
  • 1
    In my case I had to do something a little bit different. I added this to my application.js file: `import Rails from '@rails/ujs'; Rails.start();` – dani24 Jan 12 '22 at 13:22
2

based on this answer Delete link sends "Get" instead of "Delete" in Rails 3 view

I added

<%= csrf_meta_tag %>

in header, which fixed the issue

Community
  • 1
  • 1
wwli
  • 2,623
  • 6
  • 30
  • 45