TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Auto-saving Rails forms with Turbo Streams

13 pointsby strzibny4 months ago

2 comments

Kerrick4 months ago
Forgive me if I&#x27;m wrong, but I think you can avoid the extra `&lt;div&gt;` element and `formTarget`. You can use `this.element` to do so [0].<p><pre><code> import { Controller } from &quot;@hotwired&#x2F;stimulus&quot;; export default class extends Controller { submit(event) { event.preventDefault(); this.element.requestSubmit(); } } </code></pre> and<p><pre><code> &lt;%= form_with(model: post, url: post_path(post), data: { &quot;controller&quot;: &quot;autosave&quot; }) do |form| %&gt; &lt;%= form.label :title %&gt; &lt;%= form.text_field :title, class: &quot;input&quot;, data: { action: &quot;blur-&gt;autosave#submit&quot; } %&gt; &lt;turbo-frame id=&quot;title-status&quot;&gt; &lt;&#x2F;turbo-frame&gt; &lt;% end %&gt; </code></pre> [0]: <a href="https:&#x2F;&#x2F;stimulus.hotwired.dev&#x2F;reference&#x2F;controllers#properties" rel="nofollow">https:&#x2F;&#x2F;stimulus.hotwired.dev&#x2F;reference&#x2F;controllers#properti...</a>
xutopia4 months ago
Honestly Turbo Streams and Hotwire have been a game changer for me. I can do so much with so little code. I can’t believe so many people are stuck in react hell.
评论 #42647628 未加载