[RUBY] Phenomenon that HTTP becomes GET even if method:: delete in link_to method

Introduction

Here's a summary of what I stumbled upon when trying to implement the delete feature using the link_to method and how to solve it.

error contents

I got a routing error like "I searched for HTTP [GET], but there is no such thing".

HTTP method default for link_to method

Since the link_to method is the role of the a tag in HTML, it is mainly used when transitioning pages. Therefore, unless you specify a method, the HTTP method will be GET.

method :: Reason for delete

As mentioned earlier, the link_to method is GET by default, so you need to specify the method separately.

Error resolution

It's a trick, but change the link_to method to the button_to method. The design changes a little, but the function can be implemented as intended.

Finally

In Rails6, webpack was the default, and it seemed that it didn't load properly. Until now, this error did not occur, but since I started making original applications, I have come to see it ... The cause is still a mystery.

Recommended Posts

Phenomenon that HTTP becomes GET even if method:: delete in link_to method
If the HTTP method is not specified, the browser side requests with GET
Phenomenon that cannot log out even though it is described in devise