@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:
the link must use button_to, rather than a link_to
the button needs a couple extra classes to style it like an <a> if that's what we want
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.
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:
button_to
, rather than alink_to
<a>
if that's what we wantTurbo supposedly allows you to do a
link_to
withdata: { 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 Railsbutton_to
helper builds a form and a button, as you probably know.