Jese Leos

HTTP Post with a Link_To in Rails 7

I have been migrating a small app to Rails 7.x. The app has not been touched in a couple of years (Rails 5-ish with webpacker). I decided it would be simpler to start anew and just copy over the parts I needed.

One thing I noticed on a new app without RJS installed was that setting the HTTP method on links was not working.

There are two ways to fix this. One is to just use button_to instead. This is arguably better since it actually does a POST (and submit). However, if you need/want to continue using link_to, you can instead swap the method for a turbo_method.

<li>
  <%= link_to "Sign Out", logout_path, data: {turbo_method: :delete}, aria: {label: "Sign out of How I VSCode"}, class: "nav-link" %>
</li>