简体   繁体   中英

Rails: DELETE method not working - GET triggered

I'm using scaffolding for a part of my app and now detected that the delete buttons are not working. Using the following link

<%= link_to 'Destroy', user_certification, :confirm => "Are you sure?", :method => :delete %>

When I'm using the link, I'm receiving the the 'show' action back.

Log

Started GET "/user_certifications" for ::1 at 2020-02-17 14:37:45 +0000 Processing by UserCertificationsController#index as HTML

I got JS loaded in the gemfile and the application.js

GEMFILE

gem 'sprockets-rails'
gem 'jquery-rails'

application.js

//= require jquery
//= require jquery_ujs
//= require rails-ujs

I checked several solutions, but fail to make it work. Perhaps someone has a hint?

我在 Ruby on Rails 6.1 中也遇到了同样的问题 后来发现原因是由于我在 javascript 文件中放置的 Bootstrap 行。删除它后,destroy 工作正常。

So it seems like when you add bootstrap via add yarn bootstrap jquery popper.js and then when you import bootstrap in your application.js, it seems to be conflicting with the @rails/ujs and due to which the delete functionality is disabled.

Just remove bootstrap from application.js, add a CDN to use bootstrap and the delete functionality works perfectly fine. This also resolves the problem with devise Sign Out functionality as its the same delete user session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM