MushroomObserver / mushroom-observer

A website for sharing observations of mushrooms.
https://mushroomobserver.org
MIT License
77 stars 26 forks source link

Fix "Turn off admin mode" link in nav menu #2197

Closed nimmolo closed 1 week ago

nimmolo commented 1 week ago

Fixes #2168. Adds test.

@JoeCohen - In case you tried to fix this and got stumped, this link wasn't working because it needs to submit a "POST" request. (You can confirm that in the routes, and also in the controller — this is handled by the :create action.)

Here's how to build non-GET links like this:

Turbo supposedly allows you to do a link_to with data: { turbo_method: :post } but in reality (at least on MO) it doesn't work, the CSRF stops the link from working. Also, the Turbo docs themselves state "you should also consider that for accessibility reasons, it’s better to use actual forms and buttons for anything that’s not a GET." The Rails button_to helper builds a form and a button, as you probably know.