This library helps port some functionality from rails-ujs to Turbo.
If you've ever used link_to
with remote: true
and are thinking about using Turbo as a replacement to UJS - you'll need to do some extra work. However, Turbo give us everything we need to port over this functionality.
Thus, this library.
With this library, you just need to make some slight changes. For example,
Before
<%= link_to "Delete article", @article, remote: true, method: :delete %>
After
<%= link_to "Delete article", @article, data: { controller: "link-method", method: "delete" } %>
The idea is to continue moving forward with Turbo with minimal changes to existing app code.
yarn add @foxglovetech/turbo-form
The first you'll want to do is register the controllers:
import {
ConfirmController,
LinkMethodController,
} from "@foxglovetech/turbo-form";
const application = Application.start();
application.register("confirm", ConfirmController);
application.register("link-method", LinkMethodController);
If you're looking for a confirmation dialog:
<%= button_to "Delete This", some_path(resource_name), data: { controller: "confirm", confirm_message: "Are you sure?" }, method: :delete %>
If you need a link to make a request:
<%= link_to "Duplicate", some_path(resource_name), data: { controller: "link-method", method: "post" } %>
Checkout the CONTRIBUTING for info on how to help out with contributions/development.
This project is licensed under the MIT License