hotwired / hotwire-rails

Use Hotwire in your Ruby on Rails app
https://hotwired.dev
MIT License
971 stars 27 forks source link

Link_to with method delete uses GET instead of Delete #18

Closed m21ecom closed 3 years ago

m21ecom commented 3 years ago

To reproduce this issue I created a new Project using Rails 6.1.1 and adding and installing the Hotwire Rails gem. After that I scaffolded a new Model (test) and tried to delete a test object. For this i clicked on the link Destroy on the tests_url <td><%= link_to 'Destroy', test, method: :delete, data: { confirm: 'Are you sure?' } %></td> Which in gets rendered to: <a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/tests/1">Destroy</a>

When I click on this link I expect the Request to use the http method DELETE, instead if this, it uses GET. So instead of being redirected to the tests_url, it opens the show page of the given test. Also the modal data: { confirm: 'Are you sure?' } doesn't appear .

seanpdoyle commented 3 years ago

@schulte2003 Turbo's compatibility and incompatibility with link_to ..., method: ... is documented in the hotwired/turbo-rails README.

In the short term, have you tried replacing link_to "Destroy" with a button_to call instead?

m21ecom commented 3 years ago

Thank you that solved the Problem