Rails 7.0.4 - link_to method: :post no longer works?

I am upgrading a 6.x app to 7.0.4

I am noticing that a couple of links which were POST-ing to to a controller are now using GET.

Both links use the link_to method: :post option.

The guide implies that Rails RJS has been replaced by Turbo.

( the link_to API documentation mentions that the method: option has been deprecated along with RJS )

I can see that adding data: {turbo_method: :post} on the link initiates a post request - but it also uses fetch. I would not want to restructure my views to accommodate this. How can I have the RJS functionality back?

What I would like is for the link to submit with a post request to the controller.

I could replace these links with button_to, but if possible, Iā€™d prefer to still use the link_to.

What do you mean by It does fetch?

You have to choose if you want to use Turbo or you can always remove turbo and add the UJS lib back to your JS bundle.

1 Like

Thank you.

I installed the @rails/ujs package + imported it in application.js, and commented out the @hotwired/turbo-rails import.

The UJS methods now work.

Seems like I need to give up on Turbo, including Turbolinks in order to use UJS?

Turbo supports similar functionality:

link_to "Something", some_path, data: { turbo_method: :post }
1 Like