Skip to content

Commit 6b3c858

Browse files
committed
Replace jquery-ujs with @hotwired/turbo
Replace our client-side dependency on `jquery-ujs` with [@hotwired/turbo][] through the `turbo-rails` gem. Other than swapping some [config/importmap.rb](./config/importmap.rb) entries, 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 3904f3d commit 6b3c858

File tree

9 files changed

+17
-10
lines changed

9 files changed

+17
-10
lines changed

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ PATH
44
administrate (0.19.0)
55
actionpack (>= 5.0)
66
actionview (>= 5.0)
7+
activejob (>= 5.0)
78
activerecord (>= 5.0)
89
importmap-rails
910
kaminari (>= 1.0)
1011
sassc-rails (~> 2.1)
1112
selectize-rails (~> 0.6)
1213
stimulus-rails
14+
turbo-rails
1315

1416
GEM
1517
remote: https://rubygems.org/
@@ -314,6 +316,10 @@ GEM
314316
tilt (2.2.0)
315317
timecop (0.9.8)
316318
timeout (0.4.0)
319+
turbo-rails (1.5.0)
320+
actionpack (>= 6.0.0)
321+
activejob (>= 6.0.0)
322+
railties (>= 6.0.0)
317323
tzinfo (2.0.6)
318324
concurrent-ruby (~> 1.0)
319325
uglifier (4.2.0)

administrate.gemspec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ Gem::Specification.new do |s|
1717
s.add_dependency "actionview", ">= 5.0"
1818
s.add_dependency "activerecord", ">= 5.0"
1919

20+
# will be optional if https://github.com/hotwired/turbo-rails/pull/479 merges
21+
s.add_dependency "activejob", ">= 5.0"
22+
2023
s.add_dependency "importmap-rails"
2124
s.add_dependency "stimulus-rails"
25+
s.add_dependency "turbo-rails"
2226
s.add_dependency "kaminari", ">= 1.0"
2327
s.add_dependency "sassc-rails", "~> 2.1"
2428
s.add_dependency "selectize-rails", "~> 0.6"
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
22

33
import jQuery from "jquery"
4-
import Rails from "jquery-ujs"
4+
import "@hotwired/turbo"
55
import "selectize"
66

77
import "./controllers"
8-
9-
Rails(jQuery)

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
@@ -10,7 +10,7 @@ by providing a `content_for(:javascript)` block.
1010
<%= javascript_importmap_tags "administrate/application" %>
1111

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

1616
<%= 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>

config/importmap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
pin "administrate/application", preload: true
66

77
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.7.0/dist/jquery.js", preload: true
8-
pin "jquery-ujs", to: "https://ga.jspm.io/npm:jquery-ujs@1.2.3/src/rails.js", preload: true
98
pin "@hotwired/stimulus", to: "stimulus.js", preload: true
109
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
10+
pin "@hotwired/turbo", to: "turbo.js", preload: true
1111
pin "selectize", to: "https://ga.jspm.io/npm:selectize.js@0.12.12/dist/js/selectize.js"
1212
pin "microplugin", to: "https://ga.jspm.io/npm:microplugin@0.0.3/src/microplugin.js"
1313
pin "sifter", to: "https://ga.jspm.io/npm:sifter@0.5.3/sifter.js"

lib/administrate/engine.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "importmap-rails"
22
require "stimulus-rails"
3+
require "turbo-rails"
34
require "kaminari"
45
require "sassc-rails"
56
require "selectize-rails"

spec/example_app/app/views/admin/customers/_collection_item_actions.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[namespace, resource],
1313
class: "text-color-red",
1414
method: :delete,
15-
data: { confirm: t("administrate.actions.confirm") }
15+
data: { turbo_confirm: t("administrate.actions.confirm") }
1616
) if authorized_action?(resource, :destroy) %></td>
1717
<% end %>
1818

0 commit comments

Comments
 (0)