Search code examples
ruby-on-railsruby-on-rails-5

Under Rails 5, using helper link_to with method delete issues a get and object#show instead of object#destroy


I am migrating to Rail 5.2.3 and found that my delete code is failing. When I press the "Delete Object" button, it routes to object#show instead of object#destroy. This code works well under Rails 4, but is failing under Rails 5.

The html.erb module includes:

<%= link_to('Delete Object', {action: :destroy, class: 'btn btn-warning kc-wide'}, method: :delete, data: {confirm: 'Are you sure?', disable_with: "Processing..."}) %>

The generated code is:

<a data-confirm="Are you sure?" data-disable-with="Processing..." rel="nofollow" data-method="delete" href="/admin/objects/414?class=btn+btn-warning+kc-wide">Delete Object</a>

Solution

  • I finally diagnosed the problem as found here (https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts). Since rails-ujs is now contained within Rails 5, I removed references to it from my code. Yes, the old gem should not be bundled within Gemfile. However, to access it, it still must be included within the JavaScript manifest, such as in application.js within the Asset Pipeline.

    //= require rails-ujs