Rails Form won't submit after redirecting from another page

65 views Asked by At

This is a weird one and I believe it has something to do with how Turbo works. So I have an update form on one of my screens that looks something like this:

<%= form_with model: @user, url: user_settings_path(user_id: @user.id), method: :patch do |form| %>
  # Form fields go here
<% end &>

Now, when I go to that page that has that form and I reload the page, the form will submit successfully.

But if I navigate through my app, let's say go to Home Screen -> Some Other Info screen -> and then to that screen with the form, the form will NOT submit and nothing will happen(I checked the console).

And it's not only with this one form, it's site wide issue I have which, again, I believe it has something to do with Turbo but I'm not sure what.

I tried setting this in application.js by this answer but it didn't help:

Turbo.setFormMode("on" | "off" | "optin")
1

There are 1 answers

1
rna On

I guess this issue occurs due to some limitations from the HTML side. I did face a similar issue and tried the {html: {'data-turbo': false}} like below:

<%= form_with model: @user, url: user_settings_path(user_id: @user.id), method: :patch, {html: {'data-turbo': false}} do |form| %>
  # Form fields go here
<% end &>

Hopefully, it works for you as well.