Skip to content

Commit 965dc25

Browse files
committed
Replace jquery-ujs with @hotwired/turbo
Replace our client-side dependency on `jquery-ujs` with [@hotwired/turbo][]. In addition to adding an entry to the `package.json` file, this commit replaces `[data-confirm]` attributes with `[data-turbo-confirm]`, and `[data-method]` attributes with `[data-turbo-method]`. In an effort to minimize the diff, this commit *does not* replace the `link_to` calls made with `method: :delete` with [button_to][] calls. Ideally, they'd utilize `button_to` to render a `<form>` element for the destructive action. In the future, once that change is complete, the `data: {turbo_method: :delete}` attributes can once again be passed as `method: :delete` options. [@hotwired/turbo]: https://turbo.hotwired.dev [turbo-rails]: https://github.com/hotwired/turbo-rails [link_to]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to [button_to]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
1 parent ee358f4 commit 965dc25

File tree

13 files changed

+4372
-1004
lines changed

13 files changed

+4372
-1004
lines changed

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ GEM
300300
thor (1.3.0)
301301
timecop (0.9.8)
302302
timeout (0.4.0)
303+
turbo-rails (1.5.0)
304+
actionpack (>= 6.0.0)
305+
activejob (>= 6.0.0)
306+
railties (>= 6.0.0)
303307
tzinfo (2.0.6)
304308
concurrent-ruby (~> 1.0)
305309
uglifier (4.2.0)

app/assets/builds/administrate/application.js

Lines changed: 4349 additions & 989 deletions
Large diffs are not rendered by default.

app/assets/builds/administrate/application.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./add_jquery";
22

3-
import {} from "jquery-ujs";
3+
import "@hotwired/turbo";
44
import "selectize/dist/js/selectize.min.js";
55

66
import "./controllers";

app/assets/javascripts/administrate/controllers/table_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class extends Controller {
1616
var dataUrl = $(event.target).closest("tr").data("url");
1717
var selection = window.getSelection().toString();
1818
if (selection.length === 0 && dataUrl) {
19-
window.location = window.location.protocol + '//' + window.location.host + dataUrl;
19+
Turbo.visit(dataUrl);
2020
}
2121
}
2222
}

app/controllers/administrate/application_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def update
6161
redirect_to(
6262
after_resource_updated_path(requested_resource),
6363
notice: translate_with_resource("update.success"),
64+
status: :see_other,
6465
)
6566
else
6667
render :edit, locals: {
@@ -75,7 +76,7 @@ def destroy
7576
else
7677
flash[:error] = requested_resource.errors.full_messages.join("<br/>")
7778
end
78-
redirect_to after_resource_destroyed_path(requested_resource)
79+
redirect_to after_resource_destroyed_path(requested_resource), status: :see_other
7980
end
8081

8182
private

app/views/administrate/application/_collection_item_actions.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
t("administrate.actions.destroy"),
1212
[namespace, resource],
1313
class: "text-color-red",
14-
method: :delete,
15-
data: { confirm: t("administrate.actions.confirm") }
14+
data: { turbo_method: :delete, turbo_confirm: t("administrate.actions.confirm") }
1615
) if accessible_action?(resource, :destroy) %></td>
1716
<% end %>

app/views/administrate/application/_javascript.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ by providing a `content_for(:javascript)` block.
88
%>
99

1010
<% Administrate::Engine.javascripts.each do |js_path| %>
11-
<%= javascript_include_tag js_path %>
11+
<%= javascript_include_tag js_path, "data-turbo-track": "reload", defer: true %>
1212
<% end %>
1313

1414
<%= yield :javascript %>

app/views/administrate/application/show.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ as well as a link to its edit page.
3434
t("administrate.actions.destroy"),
3535
[namespace, page.resource],
3636
class: "button button--danger",
37-
method: :delete,
38-
data: { confirm: t("administrate.actions.confirm") }
37+
data: { turbo_method: :delete, turbo_confirm: t("administrate.actions.confirm") }
3938
) if accessible_action?(page.resource, :destroy) %>
4039
</div>
4140
</header>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
},
77
"dependencies": {
88
"@hotwired/stimulus": "^3.2.2",
9+
"@hotwired/turbo": "^7.3.0",
910
"esbuild": "^0.18.11",
1011
"jquery": "^3.7.0",
11-
"jquery-ujs": "^1.2.3",
1212
"sass": "^1.63.6",
1313
"selectize": "^0.12.6"
1414
},

0 commit comments

Comments
 (0)