Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms don't have to redirect #32

Closed
wants to merge 1 commit into from

Conversation

dsazup
Copy link

@dsazup dsazup commented Dec 24, 2020

Hey all. I was playing around with hotwire and it's awesome. I was trying to see if it can replace my current setup. Basically it's using this gem - https://github.com/jorgemanrubia/turbolinks_render, which is really awesome. When you submit a form it just replaces the whole content with new content. Form validations are non issue this way, redirects are working too etc.

Hotwire almost replaces this gem, however there is a slight problem. Forms must redirect or use turbo frames. I don't really understand why forms must redirect, but I am sure there is a reason for it so I would be interested to hear it.

Since I don't understand why they have to redirect I think it's unnecessary, so this is a POC of how I think it should work. You submit a form without any frames - it replaces the whole content. Behind the scenes it does simulated turbo visit with either redirected location or the current location.

This way, even when you use something like devise for authentication, you can make the devise form to be ajax based very easily - no need to edit the views & controllers to add turbo frames to it. The same goes for any form really. No need to add turbo frames, by default it just replaces the whole body. However you can still return something like

  <%= turbo_stream.replace "form" do %>
    hi world
  <% end %>

and it still works, only the #form is replaced.


Please let me know if you would be interested to continue with this - I will then look into tests. If not, feel free to just close it. ✌️

@dsazup
Copy link
Author

dsazup commented Dec 29, 2020

#39 looks like a better solution.

@dsazup dsazup closed this Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant